Rigidbody Movement

I’ve just picked up the engine this week and I’m tying to get to grips with it. I’ve been playing with it here.

Right now I have a very simple scene where the player moves around a stage. I’ve been using translate, but would like to start moving onto rigidbody forces. I’ve tried implementing it whenever the player jumps, but it doesn’t appear to do anything.

PlayerMovement.prototype.userInputControl = function()
{
    if ((this.app.keyboard.wasReleased(pc.input.KEY_SPACE)) && (this.grounded === true))
    {
        this.entity.rigidbody.applyForce(0,1,0);
        this.grounded = false;
    }
};

A couple of things to remember about forces.

“Newton’s First Law of Motion states that a body at rest will remain at rest unless an outside force acts on it, and a body in motion at a constant velocity will remain in motion in a straight line unless acted upon by an outside force.”

Calling applyForce will only apply force to the rigid body for that frame so at the moment, your jump logic is only applying one frame of force to the rigid body.

Where you want an instant change of velocity, applyImpulse would be better.

If you are going to use forces and apply it every frame (like what you are trying to do with forward and back), be careful as you can get yourself in a situation where the rigidbody reaches really high and controllable velocities as the force continuously accelerates the object unless you add dampening/counteracting forces.

1 Like