Rigidbody character not falling with gravity

I’m trying out using a Rigidbody for my game characters rather than Character Controllers because it seems I have easier options for what I’m doing later. Anyway, I’m using rigidBody.AddForce(moveDirection) where the moveDirection comes from the horizontal and vertical inputs to move the character around the screen. The problem is, that when I fall off of an edge, gravity stops working when I let go of the controls. The character falls while moving, but not while standing still. I can’t figure it out. Project Gravity is set to -9.81 on the Y axis. Character’s Mass is 2. Drag is 0. Angular Drag is 0.05

The other thing that I don’t understand is that I have to shrink him down all the way until my scale under transform is around 0.2 just for him to fall at all even with my issue. The model was made with MakeHuman and Blender and the scale factor on the import is 1.

Code for the movement is:

using UnityEngine;
using System.Collections;

public class WeightLifterDudeMovement : MonoBehaviour {

    Rigidbody rigidBody;
    Animator anim;

    bool allowMovement;
    public float moveSpeed = 10f;

    Vector3 moveDirection;


    void Start () {

        rigidBody = GetComponent<Rigidbody>();
        anim = GetComponent<Animator>();  
   
    }

    void Update()
    {

        GetInput();
        rigidBody.transform.LookAt(transform.position + moveDirection);
        rigidBody.AddForce(moveDirection);
        //rigidBody.velocity = moveDirection;

    }

    void GetInput()
    {
        float hMovement = Input.GetAxis("Horizontal");
        float vMovement = Input.GetAxis("Vertical");

        moveDirection = new Vector3(hMovement * moveSpeed, 0.0f, vMovement * moveSpeed);

        if (moveDirection != Vector3.zero)
        {
            anim.SetBool("isWalking", true);
        }
        else
        {
            anim.SetBool("isWalking", false);
        }
    }

}

And this is the result of things so far.


https://www.youtube.com/watch?v=oZurrJ_8tCI

Can someone point me in the right direction? Thanks.

I found the problem with the gravity. I am using Apply Root Motion to my character for movement. I’m really hoping to adapt this feature for the realism. When I shut it off, the character falls and works properly. Is there a way around this so I can still use root motion and have the gravity work correctly?

1 Like

Try playing around with Animate Physics. Check it if it’s not, or vice versa.

And you would want to move rigidbodies in FixedUpdate instead

Did anyone ever find a fix for this?

Their fix, had they found one 2+ years ago or whatever, may or may not even be relevant to you.
You should post a thread on the forums, if you are stuck, including your code and a description of what’s happening vs. what the desired outcome is.

Then, people might be able to assist you. :slight_smile:

Well since someone seems to need to get it going, might as well chime in. First guesses considering I’ve been there, character model just is not set up properly. Capsule collider with kinematic would probably fix I’m right up (not optimal but I’tll get ya going for prototyping). You need a physics object to apply physics to :slight_smile:

I am facing the same issue, any idea on how to solve?

its definitely a bug. I resolved it by reapply the 2D box collider on the object and gravity started to work again.

None of the above is related to 2D physics. What bug are you referring to?

So I’m most likely coming after the war. Lots of good solution in here, but my issue came from something else.
Basically : the mesh attached to my player wasn’t touching the ground (but reacting to my controls).
Eventually, it was because my box collider and rigid body were applied to my player, not to the mesh that was attached to it. So i switched all that to my child-mesh et voilà !
(if anyone comes across that issue and has tried everything else)