Smooth rotation with CrossPlatformInput
Hello all. So, Quaternion.Lerp is not working. After mouse up, rotation of object restored instantly. In first I thinked that problem in function OnPointerUp, because in Update function all works, but of course Update does not allow to turn object normally. I decided create new function for rotation, but knowed that this not solve for problem. So, whats the problem? Thanks for help.
namespace UnityStandardAssets.CrossPlatformInput { public class TouchPad : MonoBehaviour, IPointerDownHandler, IPointerUpHandler, IDragHandler {
public Quaternion startPos;
public Quaternion currentRot;
public float rotS = 2f;
void Start() {
startPos = transform.rotation;
}
void Update () {
currentRot = transform.rotation;
}
public void OnDrag (PointerEventData data) {
float angle = Mathf.Atan2 (startPos.y + (data.position.y - transform.position.y), startPos.x + (data.position.x - transform.position.x)) * Mathf.Rad2Deg;
transform.rotation = Quaternion.Euler (0, 0, angle);
}
public void OnPointerUp (PointerEventData data) {
RestoreRot ();
}
void RestoreRot () {
float t =+ Time.deltaTime * rotS;
transform.rotation = Quaternion.Lerp (startPos, currentRot, t);
}
}
}
Your answer
Follow this Question
Related Questions
Rotate on Transform.localeulerAngels smoothly 0 Answers
Restrict second touch 0 Answers
How would you rotate smoothly? 0 Answers
How can I make my game object move like this? 0 Answers
beginners scripting problem using rotate and constant force 0 Answers