Game Development Community

Jumping

by Le Roi · in Torque Game Builder · 06/28/2006 (3:22 am) · 5 replies

Can anybody enligthen me to get proper jumping going ?

I do a setConstantForce on the player , however it is not as smooth as I would hope for ?

Thanks
Le Roi

#1
06/28/2006 (6:30 am)
I've been playing around with jumping code the past few days and I'm pretty happy with the way this works.

1) if the player state is not jumping
a) set an impulse force on the player in the -y direction
b) set a constant force on the player in the +y direction (gravity)
c) set the player state to jumping


In my t2dSceneObject::Oncollision method

1) if the $srcObject is the player
a) set the contant force on the player to 0
b) set the player state to onGround


This is all taken from the platform tutorial on TDN. You will have to play around with the numbers you are using for the impulseForce and the constantForce, but you should be able to achive something acceptable.

My only problem is now, if I want to use 2 animations, one for the jump UP and one for the landing. I have no way to tell when the player reaches the apex of their jump so I can change the animation.
#2
06/28/2006 (11:36 am)
In our pack i'm creating a t2dPath which the player travels on when jumping. Aside from some issues with limitations in t2dPath, it works really well.
#3
06/28/2006 (11:59 am)
You really shouldn't use paths for jumping. Ian's was pretty good, except for setting the constant force to 0. You might want the player to be able to walk down ramps. You also might want to check the normal of the collision before you set it to onGround for the case that the player jumps and hits his head or jumps into a wall.
#4
06/28/2006 (12:42 pm)
Thomas,

There are still major problems with movement along a platform which a constant force (i.e. gravity) applied to the player. There is a noticeable slowdown in X direction movement with a constant force in Y continually pushing the player into a platform compared to no constant force. This is why some people (including myself) had suggested in other threads to just turn gravity off on a platform.

There is a cure if the collisionMaxIterations is set to a number larger than 1. I just tried it with 4 and there is occasional stuttering, but movement speed again equals what it would be if gravity was turned off.
#5
06/29/2006 (2:34 am)
You may consider turning up the mass on your platforms. Along with collisionsMaxIterations (btw, 2 should be fine), mass can have a profound effect on physics responses.