Best way to make something jump?
Posted: Thu May 06, 2010 7:50 am
Hey,
I'm just working on something basic, and am trying to get a player controlled sphere to jump off a surface. I have a triangle mesh loaded up, as well as a few boxes and ball entities around. I want my ball to jump, while in contact with the ground, so when it leaves, it cannot jump and thus will not fly.
This is the simple jump code.
I use the events system each entity seems to have to hook this up.
But when I use this code, I am able to fly, One single collision with something then anytime I press RB I jump regardless of contact with the ground. Tried the no immediate event as well, and same effect.
Also, after I get this working I would like to take into account the normal of the collision, so that when jumping off a slope, I will not leap straight up.
Anyway, any assistance would be appreciated.
I'm just working on something basic, and am trying to get a player controlled sphere to jump off a surface. I have a triangle mesh loaded up, as well as a few boxes and ball entities around. I want my ball to jump, while in contact with the ground, so when it leaves, it cannot jump and thus will not fly.
This is the simple jump code.
Code: Select all
public void Jump(Entity sender, Entity other, CollisionPair collisionPair)
{
if (g_Controller.GET.IsButtonDown(Button.RB))
{
g_NetworkManager.GET.ApplyForce(g_Constants.NetworkControllingPlayer, JumpForce);
}
}
Code: Select all
public void BuildDefaultBall()
{
this.BodyPhysics = new Sphere(MotionState.defaultState, g_Constants.PlayerMarbleRadius, g_Constants.GET.MarbleSettings.MarbleMass);
BodyPhysics.eventManager.addEventHook(new EventHandlerCollisionPairCollidingImmediate(Jump));
...
Also, after I get this working I would like to take into account the normal of the collision, so that when jumping off a slope, I will not leap straight up.
Anyway, any assistance would be appreciated.