- Home /
Rotate UI Image cirlce around self OnMouseclick
Hi good day! I'm having a problem wanting to rotate an Image in the UI that is a circle, the idea is simple that the circle when pressed with the mouse or a touch of the cel you can move it on its own axis following the circular movement of the mouse or finger . But the problem is that when you click on the circle it automatically rotates and then from that given angle it starts spinning based on the mouseposition.
v3Pos = target.position;
v3Pos = Input.mousePosition - v3Pos;
angle = Mathf.Atan2(v3Pos.x, v3Pos.y) * Mathf.Rad2Deg;
transform.rotation = Quaternion.AxisAngle(angle,Vector3.forward);
Thank you very much to anyone for the contribution to advance!
i dont iunderstand what yo uprettend to get.. can you make a paint/draw to exatcly udnerstand what you need?
Thanks!
Hello! what I try is that when the user clicks on the circle it rotates on its axis following the mouse direction. $$anonymous$$y problem is that when the user presses the circle for the first time, the image moves according to the degree that v3Pos forms, what I'm looking for is that it does not move on the first click but when the mouse is moving. I hope it gets better understood.
Then you need the position of the initial mouse click and its current position to then calculate how much its changed and use that change to set the rotation.
Answer by Mania1 · Jul 03, 2019 at 08:30 PM
@Bciam Thanks for the answer, but it still does not work, when i use Atan2 it gives me the position of mouse and rotate the circle according to where the mouse goes, but when you move the position of the image changes to the initial angle. What I'm looking for is that the circle can move on its z axis but not alter the last angle that was.