Are States Accumulative?

Hi,

Trying to work out a jump motion using states:

State 1 - Normal

  • Keyboard sensors for “normal” (i.e. X-Y) force motion
  • Keyboard sensor (“spacebar”) -> State Actuator (“Add State 2”)

State 2 - Rising

  • Always Sensor -> Motion Actuator (+Z force)
  • Keyboard Sensor (invert “spacebar”) -> State Actuator (“Set State 3”)
  • Delay Sensor (10 units) -> State Actuator (“Set State 3”)

State 3 - Falling

  • Keyboard sensors for “normal” (i.e. X-Y) force motion
  • Ray Sensor (-Z) -> State Actuator (“Set State 1”)

I want to be able to control the motion of the cube even as it’s rising or falling, but I don’t want to re-write the X-Y controls over and over, so I’m hoping to save some work by using the controls from state 1 in state 2.

The problem is that if I try to jump while moving forward the cube makes a tiny little hop, then stops moving until I release the arrow key and press it again. The jump motion works fine while standing still however.

Can states be combined like this? Or am I completely misunderstanding the “Add State” actuator?

Yes you can activate multiple states at the same time:

Set -> Resets all, Sets the given states
Add -> Adds the given states to the current states
Remove -> Removes the given states from the current states
Change -> Removes the given states if current - Adds the given states if not current (for each single state)

In your case I suggest to do this:
initial 1+16

State 1 - Normal
Keyboard sensor (“spacebar”) -> State Actuator (“Add State 2+16”)

State 2 - Rising
Always Sensor -> Motion Actuator (+Z force)
Keyboard Sensor (invert “spacebar”) -> State Actuator (“Set State 3+16”)
Delay Sensor (10 units) -> State Actuator (“Set State 3+16”)

State 3 - Falling
Ray Sensor (-Z) -> State Actuator (“Set State 1+16”)

State 16 - X-Y control
Keyboard sensors for “normal” (i.e. X-Y) force motion

Thanks a lot for the idea. Separating the states makes everything much cleaner.

It turns out the problem was unrelated to states. I was using “linear velocity” to set the speed of my cube (e.g. (2,0,0) units per frame). The moment the cube rose in the air, the motion actuator was setting the +z velocity to zero and cancelling the rest of the jump.

I can fix this problem by using “force” or setting the linear velocity to “Add”, but then the cube will accelerate to infinity. Clamping the cube’s velocity in the physics panel is a quick fix, but I would really like to have separate speeds for a “walk” or “run” motion, not to mention that the clamp also limits the jump velocity (which should be the same regardless of X-Y motion).

My new question is: can one set the X-Y velocity without changing the Z velocity?