1
\$\begingroup\$

I'm working on a third person controller which uses physX to interact with the other objects (using the Rigidbody component) and Mecanim to animate the character.

All the animations used are baked to Y, and the movement on this axis is controlled by the gravity applied by the rigidbody component.

The configuration of the falling animation:

Falling animation configuration

And the character components configuration:

Character configuration

Since the falling animation doesn't have root motion on XZ, I move the character on XZ by code. Like this:

    // On the Ground
    if (IsGrounded())
    {
        GroundedMovementMgm();

        // Stores the velocity
        velocityPreFalling = rigidbody.velocity;
    }
    // Mid-Air
    else
    {
        // Continue the pre falling velocity
        rigidbody.velocity = new Vector3(velocityPreFalling.x, rigidbody.velocity.y, velocityPreFalling.z);
    }

The problem is that when the chracter starts falling and hit against a wall in mid air, it gets stuck to the wall. Here are some pics which explains the problems:

Problem - Expected

Problem - Reality

Hope someone can help me. Thanks and sory for my bad english!

PD.: I was asked for the IsGrounded() function, so I'm adding it:

    void OnCollisionEnter(Collision collision)
    {
        if (!grounded)
            TrackGrounded(collision);
    }

    void OnCollisionStay(Collision collision)
    {
        TrackGrounded(collision);
    }

    void OnCollisionExit()
    {
        grounded = false;
    }

    public bool IsGrounded()
    {
        return grounded;
    }

    private void TrackGrounded(Collision collision)
    {
        var maxHeight = capCollider.bounds.min.y + capCollider.radius * .9f;
        foreach (var contact in collision.contacts)
        {
            if (contact.point.y < maxHeight && Vector3.Angle(contact.normal, Vector3.up) < maxSlopeAngle)
            {
                grounded = true;
                break;
            }
        }
    }

I'll also add a LINK to download the project if someone wants it.

\$\endgroup\$
0

2 Answers 2

2
\$\begingroup\$

The problem was caused by the friction configuration on the character's physic material. Changing it as the image shows fixed the problem:

enter image description here

It seems that over .001 of dynamic friction and .01 of static are enough to start slowing the fall of the character when hitting a wall.

\$\endgroup\$
0
\$\begingroup\$

Most of the mecanim setup stuff is irrelevant; this question mostly rests on what IsGrounded() is doing. Whatever is happening in there to detect the ground is not working correctly, and it considers hitting the wall to be "on the ground".

\$\endgroup\$
2
  • \$\begingroup\$ The function IsGrounded() is used by me to know if I should allow the player to control the character or not, and to apply an XZ velocity to the body in order to continue the pre-fall movement. I will add the code of this function to the question. \$\endgroup\$
    – Celtc
    Aug 13, 2014 at 23:01
  • \$\begingroup\$ If the problem is that it's detecting that the character is on the ground, then it's the rigidbody component which is bugged, because it's this component who applies the gravity. And I cannot tell him, or at least I don't tell him, when the character is on the floor. I thought that this component was applying a constant force towards the ground, don't matter if it is grounded or not. \$\endgroup\$
    – Celtc
    Aug 13, 2014 at 23:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .