- Home /
Im trying to lerp a rotation when I press a key.
I'm trying to lerp a rotation of the camera when I press a key and im trying to rotate it left and right. When I press T my screen rotates right but when I press E my screen supposed to rotate the other way but it doesn't. For rotating right I put -5 on the z axis and rotating left I put a 5 in the z axis but when I press E it rotates but when I press T it rotates the same way. BTW i'm new to programming. Please help.
[Header("Rotation")]
public Quaternion RotateL;
public Quaternion RotateR;
private bool m_Jump, m_PreviouslyGrounded, m_IsGrounded;
private float smoothRotate = 5f;
public float smoothCrouch = 3f;
// Use this for initialization
void Start()
{
Normal = transform.localRotation;
NormalP = transform.localPosition;
}
// Update is called once per frame
void Update()
{
RotateSightsL();
}
public void RotateSightsL()
{
if (Input.GetKey(KeyCode.T))
{
transform.localRotation = Quaternion.Lerp(transform.localRotation, RotateR, Time.deltaTime * smoothRotate);
}
if (Input.GetKey(KeyCode.E))
{
transform.localRotation = Quaternion.Lerp(transform.localRotation, RotateL, Time.deltaTime * smoothRotate);
}
}
}
As I can see, you use smoothRotate to get the angle(aprox) that rotate per second, but I dont know how you initialize the quaternions RotateL and RotateR, I think there must be the problem, but, ignoring this I redid all but using transform.Rotate, making the code a bit simpler, and independend of pre made rotations.
public void RotateSightsL()
{
if (Input.Get$$anonymous$$ey($$anonymous$$eyCode.T))
{
transform.Rotate (transform.up, smoothRotate*Time.deltaTime);
}
if (Input.Get$$anonymous$$ey($$anonymous$$eyCode.E))
{
transform.Rotate (transform.up, -smoothRotate*Time.deltaTime);
}
}
please check if what you need
Your answer
Follow this Question
Related Questions
I need help with adding double jump to my player movement script 0 Answers
Multiple Cars not working 1 Answer
How to make FPS Camera bounce when walking 1 Answer
Distribute terrain in zones 3 Answers
sensitivity slider/ drop down help 0 Answers