Need (a lot of) help!

I am making a Sonic game, and i need help with the following…

  1. Walking, Jumping and Running
  2. Jumping, Falling, Springing, Walking and Running animations in-game
  3. Homing Attack

I may have a few more questions later…

I dont care if homing attack is impossible but i really need the other 2

None of that is impossible in the BGE, but it will take Python to implement the game mechanics (correctly, like looping). As for the animations, it’s easy to implement - here’s a tutorial on it. It’s for 2.49, I suppose, but the idea should work for 2.54.

You may consult with pro gmae designer. While I am just a game fan!

I know how to make animations i just want to make how sonic starts to gain speed then switch animations when hes going fast enough

Use Python to get the speed of Sonic, and then switch animations depending on the value returned.


from bge import logic

cont = logic.getCurrentController() # Get the controller running this script
obj = cont.owner # Get the object with this controller

spd = obj.getVelocity()

walk = cont.actuators['WalkAction'] # The walking animation actuator
run = cont.actuators['RunAction'] # The running animation actuator

if abs(spd[0]) > 5:
    cont.activate(run)
else:
    cont.activate(walk)

Even better than this would be to additionally speed up or slow down the animation depending on the speed of Sonic. Also, this code above would go into the Python controller of Sonic, with the armature’s animation actuators attached to it.

umm what?
Can u dumb it down more? (Yes i am a noob…)

Well, that script I posted above will get the Player object’s speed, and if it exceeds 5 (you can change that value yourself), then it will trigger the run actuator attached to it - otherwise, it will trigger the walking animation actuator. Plug that script into a Python controller, and attach to that an Always sensor, with true level pulse triggering (the button that looks like [’’’]). Also attach to the Python controller your two Action actuators (from the Armature object that is animating), and name them ‘WalkAction’ for the walking animation, and ‘RunAction’ for the running animation.

To be honest, if you are new to Blender, maybe you should try making something a bit simpler - there’s a lot that you need to know to implement a game in the vein of Sonic - I would recommend starting out with a game like Breakout (a very simple physics-based puzzle game) or Marble Madness (a simple physics-based maze game). You’ll pretty much have to learn Python to implement Sonic’s motions effectively.

Im not really %100 new, i just do not know how to apply animations correctly

The code kind of worked… the animations changed but when i went slower than 5, the running animation still played

EDIT: I had the wrong settings for the Action Actuators (i had them set to Loop Stop), However when i set them to Play, it will randomly do the walking animation when im over speed 5 then switch back to the running animation

Sorry about that - here’s a fixed version.


from bge import logic

cont = logic.getCurrentController() # Get the controller running this script
obj = cont.owner # Get the object with this controller

spd = obj.getVelocity()

walk = cont.actuators['WalkAction'] # The walking animation actuator
run = cont.actuators['RunAction'] # The running animation actuator

if abs(spd[0]) > 5:
    cont.activate(run)
    cont.deactivate(walk)
else:
    cont.activate(walk)
    cont.deactivate(run)

ok it worked but whenever i turn either left or right, he will keep glitching to the walking animation for like 0.1 - 2 seconds then switch back to running then a few seconds later, Do It Again

Wait, I assumed that you’re working with the game on a 2D axis, correct? I mean, it’s a side-scrolling game, in which Sonic moves on the X-axis, right? Or is he moving in all directions (or at least, X and Y)?

He is moving in all directions (X and Y of course) although i could just make it 2D

Oh, well, that code only works on the X-dimension for his walking and running - here’s another version for the X and Y dimensions.



from bge import logic  
cont = logic.getCurrentController() # Get the controller running this script 
obj = cont.owner # Get the object with this controller
spd = obj.getVelocity()  
walk = cont.actuators['WalkAction'] # The walking animation actuator 
run = cont.actuators['RunAction'] # The running animation actuator 

if max(abs(spd[0]), abs(spd[1])) > 5:     
     cont.activate(run)     
     cont.deactivate(walk) 
else:     
     cont.activate(walk)     
     cont.deactivate(run)


Well that worked!
Now i need a standing animation.
do i need to modify the code and add stuff like:


stand = cont.actuator['StandAction']

cont.activate(stand)

cont.deactivate(stand)

?

Yep, that’s correct. You’re learning Python, bit by bit. You would add another if max…statement, except you would make sure that it’s less than 0.1, for example (so, he’s standing around). If it is true, then you would activate the standing animation, and deactivate the others (also, deactivate the standing animation on the other if statements).

umm i think i did it wrong… whenever i move he still stands. Heres how i put the code in:


from bge import logic  
cont = logic.getCurrentController() # Get the controller running this script 
obj = cont.owner # Get the object with this controller
spd = obj.getVelocity()  
walk = cont.actuators['WalkAction'] # The walking animation actuator 
run = cont.actuators['RunAction'] # The running animation actuator 
stand = cont.actuator['StandAction'] # The standing animation actuator

if max(abs(spd[0]), abs(spd[1])) > 10:     
     cont.activate(run)     
     cont.deactivate(walk)
     cont.deactivate(stand) 
else:     
     cont.activate(walk)     
     cont.deactivate(run)
     cont.deactivate(stand)
if max(abs(spd[0]) < 0.1: # i also tried the "if max(abs(spd[0]), abs(spd[1])) < 0.1:
     cont.activate(stand)
     cont.deactivate(walk)
     cont.deactivate(run)

That’s close - the only thing is that the last if statement (which should check for the maximum value between the X and Y values (spd[0] and spd[1], respectively) - the one that you had commented out was correct) should be the ‘last resort,’ an else statement, while another elif statement above would be for the walking animation.

Basically, if Sonic’s moving faster than 10, play the run animation. Else, if he’s moving faster than 1, play the walking animation. Else, play the standing animation. This should work:



from bge import logic   
cont = logic.getCurrentController() # Get the controller running this script  
obj = cont.owner # Get the object with this controller 

walk = cont.actuators['WalkAction'] # The walking animation actuator  
run = cont.actuators['RunAction'] # The running animation actuator  
stand = cont.actuator['StandAction'] # The standing animation actuator  

spd = obj.getVelocity()  
movevel = max(abs(spd[0]), abs(spd[1]))

if movevel > 10:  # Play running animation
     cont.activate(run)

     cont.deactivate(walk)      
     cont.deactivate(stand)  
elif movevel > 1: # Play walking animation           
     cont.activate(walk)         
  
     cont.deactivate(run)      
     cont.deactivate(stand) 
else:     # Play standing animation
     cont.activate(stand)

     cont.deactivate(walk)
     cont.deactivate(run)


EDIT: I added a movevel variable that represents how fast he’s moving (his maximum velocity).

The code still only used the Stand Animation

Odd. What does the console say? If it’s not visible, enable it in the Help menu.

I use Blender 2.5, so the console thing isn’t in the help menu.