- Home /
Why won't my object lerp?
Here is all my code:
using UnityEngine;
using System.Collections;
public class FlashlightTurn : MonoBehaviour {
public float lookSensitivity;
public float lookSmoothDamp;
public float lookSpeed;
public Transform camera;
public Transform player;
public float cameraPan;
public Transform cam;
private float yRotation;
private float xRotation;
private float currentYRotation;
private float currentXRotation;
private float yRotationV;
private float xRotationV;
private Quaternion lookForward;
private Vector3 lookLeftLimit;
private Quaternion fromTo;
void Start () {
lookForward = transform.rotation;
// lookLeftLimit = new Vector3(0,130,0);
}
void Update () {
if (!Input.anyKey)
{
yRotation += Input.GetAxis("Mouse X") * lookSensitivity;
xRotation -= Input.GetAxis("Mouse Y") * lookSensitivity;
xRotation = Mathf.Clamp(xRotation, -30, 30);
yRotation = Mathf.Clamp(yRotation, -50, 30);
currentXRotation = Mathf.SmoothDamp(currentXRotation, xRotation, ref xRotationV, lookSmoothDamp);
currentYRotation = Mathf.SmoothDamp(currentYRotation, yRotation, ref yRotationV, lookSmoothDamp);
transform.localRotation = Quaternion.Euler(xRotation, yRotation, 0);
fromTo = Quaternion.Euler(xRotation, yRotation,0);
if(yRotation < -47)
player.transform.Rotate(-Vector3.up * Time.deltaTime * cameraPan);
else if(yRotation > 27)
player.transform.Rotate(Vector3.up * Time.deltaTime * cameraPan);
if(xRotation < -27)
cam.transform.Rotate(-Vector3.right * Time.deltaTime * cameraPan);
else if(xRotation > 27)
cam.transform.Rotate(Vector3.right * Time.deltaTime * cameraPan);
}
if(Input.GetKeyDown("w")|| Input.GetKey("s") || Input.GetKey("a") || Input.GetKey("d"))
transform.rotation = Quaternion.Lerp(transform.localRotation, lookForward, lookSpeed * Time.deltaTime);
}
}
Forget about most of the code. Its just there in case you need to look at it. The code i need help with is the last if statement. Thanks
Answer by electricsauce · Apr 19, 2013 at 12:12 PM
Is your object the child of another?
if so maybe change line 57 to: transform.localRotation = Quaternion.Lerp(transform.localRotation, lookForward, lookSpeed * Time.deltaTime);
also, lookspeed doesn't have a default value, which sets it to 0.
Your answer

Follow this Question
Related Questions
Use Lerp to rotate object 2 Answers
better way to rotate instead Coroutine 1 Answer
How can I use lerp to rotate an object multiple times? 2 Answers
Quaternion.Lerp and Vector3.MoveTowards arent smoothing 1 Answer
Rotate object: script works if applied to that object, but not if referencing object in scene 1 Answer