- Home /
Restrictions on gameobject 2D rotation?
I have a 2D gameobject that rotates fine when I move my finger around but I don’t want it to do a full round about I’ve tried a couple things with float values but can’t seem to get it to work
void Update()
{
if (Input.touchCount > 0)
{
Vector3 pos = Camera.main.WorldToScreenPoint(transform.position);
Vector3 dir = Input.mousePosition - pos;
float angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg;
transform.rotation = Quaternion.AngleAxis(-angle, Vector3.forward);
}
}
Answer by hectorux · Nov 13, 2018 at 09:43 PM
Maybe tou want a clamp? this means that the float cant be more or lees than a max or min value
So float angle = $$anonymous$$athf.Atan2(dir.y, dir.x) * $$anonymous$$athf.Clamp(float $$anonymous$$, float max); ?
no, mathf.clamp(yourValue, $$anonymous$$, max)
Your answer
Follow this Question
Related Questions
Flip over an object (smooth transition) 3 Answers
How can I limit the rotational speed of a gameObject tracking my mouse? 1 Answer
Pysics not working as expected 1 Answer
Joystick move Left Right and down, plus rotation. 0 Answers
C# Water Rotation 0 Answers