Jump with Prismatic Joint?

General discussion about Box2D tutorials
Post Reply
FelixGriffin
Posts: 2
Joined: Sun Dec 23, 2012 4:10 am

Jump with Prismatic Joint?

Post by FelixGriffin »

In the Jumping tutorial you mentioned using a prismatic joint with a motor for a realistic force on the object you jump from. I've been trying to implement it and haven't had any luck so far. Would you ever consider adding this as an advanced tutorial?
iforce2d
Site Admin
Posts: 861
Joined: Sat Dec 22, 2012 7:20 pm

Re: Jump with Prismatic Joint?

Post by iforce2d »

I had initially been thinking to do that, but I'm not so sure it's worth a whole tutorial. Maybe this thread will suffice :)

Basically you have a main (fixed rotation) body for your character, and a second body attached with a prismatic joint to function as a 'piston'. Setting the speed and max force of the prismatic joint to high values briefly (say, 5-10 timesteps at 60fps) will cause the character to jump up - or not, if he is standing on something soft like a swing-bridge. Make sure to set limits on how far the piston can move ;)

When not jumping, you set the max force for the prismatic joint to zero. This means you will probably also need another joint between these bodies, typically a distance joint to give a suspension-like feel and return the piston after the jump has completed. The rest position of the piston will be at the top of the stroke, so it will mostly be inside the main body. You can adjust the values of the frequency and damping of the distance joint, and the speed and max force of the prismatic joint when jumping, to get the right feel for your game.

Typically the mass of the piston would be smaller than the main body, but not too much smaller because you still want the prismatic joint to be able to shove the main body upwards. I think I have made the piston about half the mass of the main body most times I tried this. If you have a rotating wheel at the bottom of the piston to move the character, the mass of this wheel should also not be too much smaller than the piston.

Another reason I did not follow up on this style of jumping further, is that it can make the behavior of the game as a whole very hard to tune. When I made the 'Alone in the park' for LD48 last year I initially started with this prismatic joint style of jumping, but it turned out to be much easier to just apply an impulse upwards to make the character jump. One problem is that it feels strange for many players that the character jumps to a different height - it feels more like they are more in control if the jump height is constant. Another problem for me in that case was that I was making puzzles that involved jumping, eg. the player should not be able to jump onto this ledge, but he must be able to jump onto that ledge, etc. If you have 'bigger picture' concerns like this you might want to look for a more predictable jump style, but it all depends on the type of game you are making I guess.

My best outcome with this style of control was when I started learning iOS: YouTube Maybe I can find that project and upload the source...
Post Reply