Hi all,
Im new to unity scripting and I’ve tried to write a code to rotate object with ease on it in the only certain Axis, and I’ve wrote a code but it has a bug thats after two 360 degree of rotation its start to rotate in other axis.
I’ve tried to change the code but there was no luck
can you please guide me and tell me how can i fix it?
Thank you, really appreciate it
void OnPress() {
isDragging = true;
}
void Update() {
if (Input.touchCount > 0 && isDragging) {
theSpeed = new Vector3(-Input.touches[0].deltaPosition.x, 0.0F, 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(gameObject.transform.forward * theSpeed.x * rotationSpeed, Space.World);
}