Hello, I’m trying to rotate an object with mouse/touch input, like this
I need to hold the green circle, and drag it around 360 degrees, after which I output something.
The code I have now just mimics it.
//Image Wheel = the white wheel, defined in inspector
//Image Handle = the green handle which,while user touches it,sets isRotating to true
//float rotAngle = current angle, 0 at start
public void Update(){
if(isRotating){
Wheel.transform.rotation = Quaternion.AngleAxis(rotAngle, Vector3.forward);
rotAngle += 9f;
}
if(rotAngle > 360){
rotAngle = 0;
Debug.Log("Full circle! / Points++");
}
}
WheelHandleDown(){
isRotating = true;
}
WheelHandleUp(){
isRotating = false;
}
It rotates the wheel while the player is holding the green handle. This creates an illusion that the player is actually dragging the handle and rotating the wheel.
But the problem I have is that if I try to rotate the wheel very fast, the mouse leaves the handle and it does not rotate. If I increase the rotAngle which is increased every update while the player is “spinning” the wheel, the action looks very choppy. If I decrease it, the action looks smooth but the player can’t rotate the wheel as fast.
Is there a way to move the green handle to the mouse/touch position,without leaving the circle path?
I’ve tried various answers to similar questions, which involved sin,cos,atan functions which I still don’t understand.