Character sliding like rigidbody with physics material?

Hi, there is a way to make my character slide like if it has a rigidbody with physics material friction = 0 ?

Atm my character can stick into the walls.

1 Like

Yes, here is a general approach, modify the values to fit your needs:

  1. Add a Rigidbody component to you character

  2. Tweak any values you see fit. This includes angular drag, drag, mass for example, you can get less “sticking” with lower values

  3. Create a physics material (In case you don’t know, Assets → Create → Physics Material), or if you already have a physics material, you could just use that…

  4. On the physics material, make sure to set the friction to 0, this will lessen the “sticking”

  5. Assign this physics material to any colliders that you have on your player.

6, I assume you already have the movement working fine, with the input system you can translate that into movement Rigidbody.AddForce or Rigidbody.velocity.

Finally here are some general collision tips I found:

Ensure your character’s colliders are set up correctly and accurately represent its shape.

Implement collision detection and response logic to handle interactions with the environment.

When a collision occurs, you can apply additional forces or modify the character’s velocity to allow sliding instead of sticking.

Additionally I would experiment with your rigidbody values, let me know if you need anymore help!

So you’r using character controller + rigidbody ?

1 Like

I am just giving you a general tip to prevent sticking, I don’t even have this course, you don’t use a Rigidbody?

I for some reason thought you were asking about how to implement this with rigidbody, sorry for the confusion, lemme know if you have further questions.

Naa, im using character controller :s

1 Like

Wait can’t you just make the wall not “stick” to the player, just do what I said before but apply this to the wall with some minor differences, if you need me to elaborate, let me know.

Here’s how you can do it:

Create a physics material: In the Unity editor, go to Assets > Create > Physics Material. Name your material and adjust the friction to 0.

Apply the physics material to the walls’ colliders: Select the colliders of the walls and drag the physics material you just created onto the “Material” field in the Inspector window.

And do this to the wall, messing with the character contr is too much to do you can just do this

I already tried, it’s not working because character controller dont work with physics

1 Like

That’s odd, it works for me if I add the rigidbody and such to the walls, your project is probably set up a certain way, id check to see if this isn’t fixed later in the course, also some screenshots can help, like if your inspector and such, anything relevant.

You did something else ?

1 Like

Well, I just tried to replicate what you hade, obviously you probably have animations and stuff which could further interfere, it is probably better to get a teaching assistant who might know this, and has access to all course, @Nina, maybe you have an idea?

The Third Person Combat and Traversal course doesn’t use the Rigidbody, and instead uses a custom ForceReciever.

If the wall is not a terrain, you could add this script to the wall:

using UnityEngine;

public class CharacterRepellent : MonoBehaviour
    [SerializeField] private float pushAmount = 2.0f;

    private void OnCollisionEnter(Collision other)
        if (other.transform.TryGetComponent(out ForceReceiver forceReceiver))
            forceReceiver.AddForce(other.impulse * pushAmount);

When a collision occurs, the collider initially intersect and overlap by a small amount. The Physics engine detects this overlap and then does all the complex math required to move the colliders back to where they are only touching, not overlapping. The total amount of movement required to rectify the physics collision is stored in a field in the collision called impulse.
Since the wall is static, all of that impulse is applied to the player. This script should leverage that impulse value to push the character back by adding force to our Force Receiver. Adjust the push amount to taste.

1 Like

Thanks I was kinda stuck not knowing how to solve this, I don’t have this course so I didn’t fully understand, I should probably stick to solving rpg,3d,2d cuz those one I’ll be able to help with the most.

Under most of the courses, your answer would have been right. We complicate things with the ForceReceiver instead of the Rigidbody in the Third Person course.

1 Like

I put the script on the wall but it does not work
I tried to put a debug.log in OnCollisionEnter but it never proc, my character stick on the wall and no debug.low show off
i guess oncolisionenter is not working with character controller ?

It might not be, now that I think of it… same problem, no rigidbody… but we don’t want the rigidbody to be on the player or we’ll have some… issues…
Try putting a Rigidbody on the Wall, and mark it Kinematic, and make sure that the wall itself is marked as static at the top of the inspector.

If that doesn’t work, I"ll have to do some digging for more ideas.

It’s not working :frowning:

Ok, I’ll have to research some and see what else I can come up with.

1 Like

Thank you

Did you find a solution ?

Unfortunately, no. This may be an intrinsic defect in our ForceReciever vs Rigidbody model…
The only thing I came up with that was at all effective was preventing the player from getting there in the first place by putting up giant vertical colliders at the base of obstacles one shouldn’t jump on on. That means the character stops BEFORE getting to the hill…

Privacy & Terms