Question by
Nuno_Barros · Jun 23, 2017 at 09:14 AM ·
rotatemouse drag
How to only rotate an object with mouse dragging in the clock wise direction?
I'm developing a game in which the user has to drag an object with the mouse, but I only want the object to rotate if the user drags it in a clock wise direction. This is my code so far:
private void OnMouseDown()
{
isRotating = true;
dir = Input.mousePosition - Camera.main.WorldToScreenPoint(transform.position);
angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg;
qStart = Quaternion.Inverse(Quaternion.AngleAxis(angle, Vector3.down)) * transform.rotation;
}
private void OnMouseDrag()
{
dir = Input.mousePosition - Camera.main.WorldToScreenPoint(transform.position);
angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg;
if (angle-1 == )
transform.rotation = Quaternion.AngleAxis(angle, Vector3.down) * qStart;
}
void OnMouseUp()
{
isRotating = false;
}
Any help would be apreciated, thank you.
Comment
Could you add a screenshot or more information of what you actually want to rotate and what you want to drag?