1
\$\begingroup\$

EDIT: It was the Animator after all. Apply Root Motion basically nullifies any physics based work.

I "know" this answer but I can't figure out what can possibly be wrong. My code is in FixedUpdate(). My Rigidbody2D has a Gravity Scale of 4 and a Mass of 1. For whatever reason a Gravity Scale of 1 just isn't strong enough to keep it from floating away. In the pictures below the little cubes should be marking each frame.

Using the below code I get a jagged leap movement. The object shoots upwards and falls like a feather.

if(Game.inputManager.GetKey("Jump").KeyPressed())
{
    yForce = 1000f;
    this.rigidbody2D.AddForce(Vector2.up*yForce);
}

sudden force

And using another suggestion I distribute the force over a second of time.

if(Game.inputManager.GetKey("Jump").KeyPressed())
    {
        addForceTimer = 1;
        yForce = 1000f;
    }
    addForceTimer -= Time.deltaTime;
    if(addForceTimer > 0)
    {
        this.rigidbody2D.AddForce(Vector2.up*yForce* Time.deltaTime*4);

    }

And I get a more desirable but still just as wrong movement where there is no hang at the top of the jump.distributed force

From what I thought I knew neither of these should be happening at all. The object shouldn't be falling at a constant speed like it is. Does anybody have any suggestions?

The character is animated if that can possibly have some sort of effect but I don't imagine it would.

\$\endgroup\$
1
\$\begingroup\$

Make sure that if the GameObject is animated that you turn off "Apply Root Motion". It is a setting on the "Animator" component. It will mess with the Physics of the object. I do not know the particulars. But I turned it off and voila, everything works fine now.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.