Hey guys,
I am trying to make an object rotate down when the player is running. It is supposed to rotate 25 degrees down and become unaffected by further camera movement meaning that when the player looks up while running the object still points towards the ground. When the player stops running it is supposed to align with the camera again. This means that the flashlight is still aligned with the players y rotation but not with his x.
The object itself is a child of the camera and the camera is a child of the player.
#pragma strict
var playerCamera : Transform;
var rotation : float;
var speed : float = 5;
private var startRotation : float;
private var startRotationWorld : float;
function Start(){
startRotation = transform.localEulerAngles.x;
}
function Update (){
print(playerCamera.eulerAngles.x);
print(transform.eulerAngles.x);
if(eventHandler.running){
transform.localEulerAngles.x = Mathf.Lerp(transform.localEulerAngles.x, rotation, Time.deltaTime * speed);
//THIS DOES NOT WORK transform.eulerAngles.x = Mathf.Lerp(transform.eulerAngles.x, 0, Time.deltaTime * speed);
}
else if(!eventHandler.running){
transform.localEulerAngles.x = Mathf.Lerp(transform.localEulerAngles.x, startRotation, Time.deltaTime * speed);
//THIS DOESN'T EITHER transform.eulerAngles.x = Mathf.Lerp(transform.eulerAngles.x, playerCamera.eulerAngles.x, Time.deltaTime * speed);
}
}