- Home /
Question by
Josenifftodd · Nov 17, 2014 at 05:44 PM ·
playerrotatenotleft
Why is left going right, and rights going left
I have used the same model as they said in the Tutorial but when I got left he goes right and when I go right he goes left.
Anyone know the solution?
#pragma strict
public var turnSmoothing : float = 15f; // A smoothing value for turning the player.
public var speedDampTime : float = 0.1f; // The damping for the speed parameter
public var smoothTurn : float = 0.2f;
private var anim : Animator; // Reference to the animator component.
function Awake ()
{
// Setting up the references.
anim = GetComponent(Animator);
}
function FixedUpdate ()
{
// Cache the inputs.
var h : float = Input.GetAxis("Horizontal");
var v : float = Input.GetAxis("Vertical");
var sneak : boolean = Input.GetButtonDown("Sneak");
MovementManagement(h, v, sneak);
}
function Update ()
{
}
function MovementManagement (horizontal : float, vertical : float, sneaking : boolean)
{
if(horizontal != 0f || vertical != 0f)
{
// ... set the players rotation and set the speed parameter to 5.5f.
Rotating(horizontal, vertical);
anim.SetFloat("Speed", 5.5f, speedDampTime, smoothTurn);
}
else
// Otherwise set the speed parameter to 0.
anim.SetFloat("Speed", 0);
}
function Rotating (horizontal : float, vertical : float)
{
// Create a new vector of the horizontal and vertical inputs.
var targetDirection : Vector3 = new Vector3(0f,horizontal,vertical);
// Create a rotation based on this new vector assuming that up is the global y axis.
var targetRotation : Quaternion = Quaternion.LookRotation(targetDirection, Vector3.up);
// Create a rotation that is an increment closer to the target rotation from the player's rotation.
var newRotation : Quaternion = Quaternion.Lerp(rigidbody.rotation, targetRotation, turnSmoothing * smoothTurn);
// Change the players rotation to this new rotation.
rigidbody.MoveRotation(newRotation);
}
Comment
var h : float = -Input.GetAxis("Horizontal");
This could work.
Answer by bubzy · Nov 17, 2014 at 05:53 PM
a dirty fix is this :
var h : float = -Input.GetAxis("Horizontal"); // the magic is in the minus :D
Your answer
![](https://koobas.hobune.stream/wayback/20220613171750im_/https://answers.unity.com/themes/thub/images/avi.jpg)