Question by
Blapple88 · Sep 16, 2016 at 04:52 AM ·
third person controllerturning
Third Person Character Controller gets stuck looking left
Hello, I'm having a little issue with the Third Person Controller that comes with Unity. When my character is facing left I often get pulled back to facing left after moving. Example gif https://i.gyazo.com/2751c248c4e078fb4338bcb67234e017.gif.
Anyone happen to know why it does this?
public void Move(Vector3 move, bool crouch, bool jump)
{
// convert the world relative moveInput vector into a local-relative
// turn amount and forward amount required to head in the desired
// direction.
if (move.magnitude > 1f) move.Normalize();
move = transform.InverseTransformDirection(move);
CheckGroundStatus();
move = Vector3.ProjectOnPlane(move, m_GroundNormal);
m_TurnAmount = Mathf.Atan2(move.x, move.z);
m_ForwardAmount = move.z;
ApplyExtraTurnRotation();
// control and velocity handling is different when grounded and airborne:
if (m_IsGrounded)
{
HandleGroundedMovement(crouch, jump);
}
else
{
HandleAirborneMovement();
}
ScaleCapsuleForCrouching(crouch);
PreventStandingInLowHeadroom();
// send input and other state parameters to the animator
UpdateAnimator(move);
}
void ApplyExtraTurnRotation()
{
// help the character turn faster (this is in addition to root rotation in the animation)
float turnSpeed = Mathf.Lerp(m_StationaryTurnSpeed, m_MovingTurnSpeed, m_ForwardAmount);
transform.Rotate(0, m_TurnAmount * turnSpeed * Time.deltaTime, 0);
}
Comment
Best Answer
Answer by GilesDMiddleton · Oct 31, 2016 at 05:52 PM
I just experienced the same thing, with my little doggy.
I'm not 100% sure, as I'm not gifted at maths.
It appears to be something to do with the aTan2 calculation - it returns PI at x=0,z=0, and that causes the self-rotation, slowly edging the W component of the rotation quaternion.
But I solved it by not reacting to that situation:
if( move.x!=0 || move.z !=0 )
ApplyExtraTurnRotation();