Search Unity

Unexplained Character Movement

Discussion in 'Navigation' started by Dimenvarog, Mar 29, 2016.

  1. Dimenvarog

    Dimenvarog

    Joined:
    Mar 29, 2016
    Posts:
    11
    I have been working with my character movement and all is going well except I cannot figure out why when the character travels up an incline it will begin to move to the left and to the right of its own accord as if being influenced by the terrain itself.

    On flat ground the character behaves properly except that I isolated panning to control the X axis rotation of the camera with the right mouse button (left mouse controls the Y axis) because it tends to increase in rotation speed and becomes hard to manage.

    My main concern is the auto correcting to terrain. I cannot seem to find anything that might be causing this to happen. Any suggestions will be greatly appreciated.

    I run an animator, rigid body, capsule collider, third person user control, third person character and nav mesh agent on my character.
    I run a rigid body and move camera script on my main camera rig. Protect camera and auto cam are on the rig as well but they are turned off.
     
  2. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    6,363
    link to a video showing what you mean.
     
  3. Dimenvarog

    Dimenvarog

    Joined:
    Mar 29, 2016
    Posts:
    11

     
    Last edited: Apr 3, 2016
  4. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    6,363
    If you are using a physics character controller it will naturally drift down the slope. Maybe that's what you're experiencing.
     
  5. Dimenvarog

    Dimenvarog

    Joined:
    Mar 29, 2016
    Posts:
    11
    How would I know if i'm using a physics controller? I have third person character, third person user control, nav mesh agent, capsule collider, rigidbody and an animator.

    When you see the character moving from right to left and back again as it climbs the ramp that is not me doing that. It is happening of its own accord. What setting could be causing this behavior?
     
    Last edited: Apr 7, 2016
  6. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    6,363
    So many things can go wrong, pack it up and I'll take a look if you want. Much easier.
     
  7. Dimenvarog

    Dimenvarog

    Joined:
    Mar 29, 2016
    Posts:
    11
    Do I just send you the Unity File or do I need to make a build and send that?
     
  8. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    6,363
    zip the project and Dropbox it here
     
  9. Dimenvarog

    Dimenvarog

    Joined:
    Mar 29, 2016
    Posts:
    11
  10. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    6,363
    Ah you are using the Unity controller, that's why it's acting weird.

    Remove the projection to tilted ground from this:
    Code (CSharp):
    1. move = Vector3.ProjectOnPlane(move, m_GroundNormal);
    into that
    Code (CSharp):
    1. move = Vector3.ProjectOnPlane(move, Vector3.up);
    As a rule of thumb you don't want to use Unity's controller as they tend to make all sorts of wacky assumptions. Use them as tutorial, learn how they move stuff and talk to the animator, handle root motion and stuff, then roll your own, that'll save on tylenol ;)
     
  11. Dimenvarog

    Dimenvarog

    Joined:
    Mar 29, 2016
    Posts:
    11
    Awesome, thanks so much.
     
    laurentlavigne likes this.