All Questions

Community

W
Max Willis
posted to: Air movement

Where do we use the "velocity" msg?

Just wondering where we use the "velocity" msg like we use the "impulse" msg for jumping?

We use the "impulse" msg in the Move State:

 if owner.is_on_floor() and event.is_action_pressed("jump"):
  _state_machine.transition_to("Move/Air", { impulse = jump_impulse })

But I can not see where we use the "velocity" msg which if I understand correctly is suppose to set our move.velocity to msg.velocity (which has not been defined?) and set the move.speed.x to the biggest value either msg.velocity.x or move.max_speed.x.

I'm still not sure what the purpose of this "velocity" msg is.

Any further explanation would be greatly appreciated!

Thanks

  • Nathan Lovato replied

    Passing the velocity to the air state is to let the air state decide if and how it preserves your velocity when going from ground to air. Here's an example of how it's done in the final demo

    if "velocity" in msg:
    	_parent.velocity = msg.velocity
    	_parent.max_speed.x = max(abs(msg.velocity.x), _parent.max_speed.x)
    

    Now, you noticed we already had that velocity in _parent.velocity. We're giving ourselves a constraint and convention to have states set themselves up with the data passed to them, to avoid making the code too hard to read later on.