I am trying to rewrite my platformer game to use Box2d, but I am stumped as to how to implement the movement correctly. Could anyone who is more knowledgeable about Box2d explain the best way to do this please?
I want to have the player move at a set speed horizontally when the arrow keys are pressed with instant acceleration and deceleration. However, I want this to be in addition to however fast the platform beneath them is moving.
So far, the best approach I've been able to come up with is to somehow always check whether there are any platforms beneath the player at any given time, and if so, attach a prismatic joint with a motor.
But what if the player wants to jump? I guess I need to somehow maintain a pointer to the joint so that I can disable it. But then what happens if the platform is deleted? It sounds like the joint will be freed, leading to the player object owning a dangling pointer to a nonexistent joint.
What can I do? I'm really confused.
I want to have the player move at a set speed horizontally when the arrow keys are pressed with instant acceleration and deceleration. However, I want this to be in addition to however fast the platform beneath them is moving.
So far, the best approach I've been able to come up with is to somehow always check whether there are any platforms beneath the player at any given time, and if so, attach a prismatic joint with a motor.
But what if the player wants to jump? I guess I need to somehow maintain a pointer to the joint so that I can disable it. But then what happens if the platform is deleted? It sounds like the joint will be freed, leading to the player object owning a dangling pointer to a nonexistent joint.
What can I do? I'm really confused.
