Search Unity

Spent time searching, still cannot find a real answer to my rigidbody problem of sticking to walls.

Discussion in 'Physics' started by Remludar, Jun 1, 2015.

  1. Remludar

    Remludar

    Joined:
    Feb 22, 2014
    Posts:
    2
    I have a fully mature game design and I'm trying to build my prototype (graphics be damned right ?) So, anyway, I need my character controls and camera to be very solid as they are a strong part of my game play.

    I have everything worked out right now, but there's a huge blight on my controls. Whenever my character moves into a surface that's perpendicular to the flat ground (a wall basically) my character sticks to it for some time.

    Now, I read plenty about how you can create a physics material and modify it to make it's friction really low, but that really isn't an answer in my opinion because while it fixes the problem, it makes the character slide in other situations where it shouldn't (like it's on ice).

    So finally to my question: How do I modify/use rigidbody behaviors such that I can stop this "sticky wall jump" behavior in a way that works for me? I'm uploading a copy of my movement script for critique.

    Please help! I'm very frustrated and I'm 100% certain that it's something simple I'm missing.
     

    Attached Files:

  2. HiddenMonk

    HiddenMonk

    Joined:
    Dec 19, 2014
    Posts:
    987
    You are applying the frictionless material to the player, however, have you tried applying the frictionless material on the wall you are colliding against? Doing this will solve the problem (somewhat).
    Now, lets say that wall is actually just a box to which you can also end up landing on top on. This would mean that box would be slippery and have that ice effect you don't want. So, you would then probably need to create a script that shoots a raycast towards the direction you are moving (or some kind of method to get the normals of the object you are hitting), and if the normals are 90 degrees (meaning its a wall), you can then get its colliders physics material, check its friction, and apply a downward force to your character to counteract the friction.
    Another way to do it would be to instead of counteracting the friction, you can just disable any force being applied to your player in the direction of the wall.

    Also, you are using Transform.Translate for your physics object, however, it is advised to use Addforce instead.