Search Unity

Character sticks to walls and objects at all but the most extreme angle of collision.

Discussion in 'Scripting' started by topherbwell, Jun 29, 2015.

  1. topherbwell

    topherbwell

    Joined:
    Jun 8, 2015
    Posts:
    180
    My character is controlled as a third person character from a very top down perspective. When my character walks into an object or wall, it sticks to the wall. The character will only slide along the wall once it is at about 70 degrees (if facing the wall directly is 0 degrees).

    The behaviour that I would like to see, is that if the character runs into a wall or object and is facing at least a 45 degree angle to the wall, that the character will slide along the wall and not just stay stationary while playing the walking animation.

    Here is my code. Any help pointing me in the right direction is appreciated!
    Code (csharp):
    1.  
    2. /*essentially, I am just using addrelative force in fixed updated for forward/back, strafe left/right.  I also have a rotation bit, but it is in the Update function as it only uses transform.rotate.*/
    3.      void FixedUpdate()
    4.      {
    5.           strafe = Input.GetAxis("Strafe") * speed;
    6.           translation = Input.GetAxis("Vertical") * speed;
    7.           strafe *= Time.deltaTime;
    8.           translation *= Time.deltaTime;
    9.           ply.velocity = newVector3(0, ply.velocity.y, 0);
    10.           ply.AddRelativeForce(newVector3(strafe, 0, 0), ForceMode.VelocityChange);
    11.           ply.AddRelativeForce(newVector3(0, 0, translation), ForceMode.VelocityChange);
    12.      }
    13.  
    14.  
     
  2. topherbwell

    topherbwell

    Joined:
    Jun 8, 2015
    Posts:
    180
    things that go BUMP in the night.
     
  3. HiddenMonk

    HiddenMonk

    Joined:
    Dec 19, 2014
    Posts:
    987
    Make sure your wall or character has a physics material with no friction.
    For testing if this is the issue, create a physics material with 0 friction and put it on both the wall collider and player collider.
     
    BrandStone and topherbwell like this.
  4. topherbwell

    topherbwell

    Joined:
    Jun 8, 2015
    Posts:
    180
    This helped. The character isn't stick to the walls nearly as bad as before. Thank you!
     
    HiddenMonk likes this.