- Home /
lerp rotation by key press
Hello guys im total beginner can you please help me with this Problem i got a code which transforms the position by pressing buttons. Now I need the same script but with two different rotate positions. Please dont be to harsh on me im total beginner. This is the code:
using UnityEngine;
using System.Collections;
public class lerp : MonoBehaviour
{
private Vector3 newPosition;
void Awake ()
{
newPosition = transform.position;
}
void Update ()
{
PositionChanging ();
}
void PositionChanging ()
{
Vector3 positionA = new Vector3(-15037,24,23166);
Vector3 positionB = new Vector3(-15037,40,23166);
if (Input.GetKeyDown (KeyCode.Q))
newPosition = positionA;
if (Input.GetKeyDown (KeyCode.E))
newPosition = positionB;
transform.position = Vector3.Lerp (transform.position, newPosition, Time.deltaTime);
}
}
http://docs.unity3d.com/ScriptReference/Transform-rotation.html
I believe this is what you're looking for.
transform.rotation = Quaternion.Slerp(transform.rotation, target, Time.deltaTime * smooth);
Can someone help me writte thise code im beginner and i dont understand c# at the moment.
This doesnt work:
using UnityEngine;
using System.Collections;
public class lerp : $$anonymous$$onoBehaviour
{
private Vector3 target;
void Awake ()
{
target = transform.rotation;
}
void Update ()
{
PositionChanging ();
}
void PositionChanging ()
{
Vector3 A = new Vector3(-15037,24,23166);
Vector3 B = new Vector3(-15037,40,23166);
if (Input.Get$$anonymous$$eyDown ($$anonymous$$eyCode.Q))
target = A;
if (Input.Get$$anonymous$$eyDown ($$anonymous$$eyCode.E))
target = B;
transform.rotation = Quaternion.Slerp(transform.rotation, target, Time.deltaTime * smooth);
}
}
Your answer
Follow this Question
Related Questions
How to use the lerp function with rotation? (C#) 1 Answer
How to Rotate Game Object in specific Angle repeatedly on Key Press? 1 Answer
How would I detect if key get pressed 2 times 2 Answers
How to ROTATE an object without slowing the ends (lerp) 3 Answers
Lerp 180 degrees while holding B and lerp back 180 degrees when let go of B. 2 Answers