In the third person platformer tutorial I noticed that if you walk in one direction and then change to the opposite direction the character will immediately switch. It won’t rotate to the new direction first, so I changed the code in the ThirdPersonController.js file:
// Grounded controls
if (grounded)
{
// Lock camera for short period when transitioning moving standing still
lockCameraTimer += Time.deltaTime;
if (isMoving != wasMoving)
lockCameraTimer = 0.0;
// We store speed and direction seperately,
// so that when the character stands still we still have a valid forward direction
// moveDirection is always normalized, and we only update it if there is user input.
if (targetDirection != Vector3.zero)
{
// If we are really slow, just snap to the target direction
/*
if (moveSpeed < walkSpeed * 0.9 grounded)
{
moveDirection = targetDirection.normalized;
}
*/
// Otherwise smoothly turn towards it
//else
//{ moveDirection = Vector3.RotateTowards(moveDirection, targetDirection, rotateSpeed * Mathf.Deg2Rad * Time.deltaTime, 1000);
moveDirection = moveDirection.normalized;
//}
}
Basically, I enforced the execution of this code bit:
moveDirection = Vector3.RotateTowards(moveDirection, targetDirection, rotateSpeed * Mathf.Deg2Rad * Time.deltaTime, 1000);
moveDirection = moveDirection.normalized;
So now it works fine, the problem is that when the character rotates to the opposite direction it does so over a circle with a wide radius. So basically if you are standing in front of a drop and you press the opposite direction you will definately fall as the character tries to rotate first.
Any idea how I can fix this?[/code]