Question by
CristianWC · May 08, 2016 at 08:56 PM ·
lerprotate objecttouchscreen
What is lerpSpeed?
I've used this script to rotate a cube by touch:
private float rotationSpeed = 10.0F;
private float lerpSpeed = 1.0F;
private Vector3 theSpeed;
private Vector3 avgSpeed;
private bool isDragging = false;
private Vector3 targetSpeedX;
void OnMouseDown() {
isDragging = true;
}
void Update() {
if (Input.GetMouseButton(0) && isDragging) {
theSpeed = new Vector3(-Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y"), 0.0F);
avgSpeed = Vector3.Lerp(avgSpeed, theSpeed, Time.deltaTime * 5);
} else {
if (isDragging) {
theSpeed = avgSpeed;
isDragging = false;
}
float i = Time.deltaTime * lerpSpeed;
theSpeed = Vector3.Lerp(theSpeed, Vector3.zero, i);
}
transform.Rotate(Camera.main.transform.up * theSpeed.x * rotationSpeed, Space.World);
transform.Rotate(Camera.main.transform.right * theSpeed.y * rotationSpeed, Space.World);
}
}
When i drag with the mouse when debug its ok, perfecto i think, but when i drag using touch in the phone theres a problem, when i drag its is fast and when i touch in another place of the screen without drag it rotates anyway, help please.
Comment
Your answer
Follow this Question
Related Questions
RotateAround an object with clamped limits 0 Answers
How to rotate smoothly 0 Answers
Unity Lean Touch. How to rotate 3D model around custom axis only with one finger 0 Answers
How do I make an object face a direction instantly? 1 Answer
how to to rotate a object in 2D to known position values 0 Answers