At the moment the rotation is nice but id like the cube to snap back in to place (to the nearest 90 degrees) when i let go of the thumb stick, i tried with it the, If eulerAngles are less than or grater than but it got confused after a while i’m learning … and i feel this way eventually the number work against each other in the end because i want it spinning on two Axis really…
public class CubeRotation : MonoBehaviour
{
public JoyStick virtualJoystick;
public float RoatitionSpeed = 20f;
private static int SnapRot;
private float LeftoOrRight;
private float UpOrDown;
private Vector3 CurrentRotation;
private void Update()
{
CurrentRotation.z = 0;
UpOrDown = virtualJoystick.Vertical();
LeftoOrRight = virtualJoystick.Horizontal();
// thunbstick rotation....
if (LeftoOrRight > 0.93f)
{
transform.Rotate(Vector3.up * -RoatitionSpeed * Time.deltaTime, Space.World);
}
else if(LeftoOrRight < -0.93f)
{
transform.Rotate(Vector3.up * RoatitionSpeed * Time.deltaTime, Space.World);
}
if(UpOrDown > 0.93f)
{
transform.Rotate(Vector3.right * RoatitionSpeed * Time.deltaTime, Space.World);
}
else if (UpOrDown < -0.93f)
{
transform.Rotate(Vector3.right * -RoatitionSpeed * Time.deltaTime, Space.World);
}
// snap rotation
SnapRot = virtualJoystick.Snaprot;
CurrentRotation = transform.rotation.eulerAngles;
if (SnapRot == 1)
{
if(CurrentRotation.x >= 0.1f && CurrentRotation.x <= 45 )
{
transform.eulerAngles = new Vector3(0,0,0);
}
else if(CurrentRotation.x >= 45.1f && CurrentRotation.x <= 90)
{
transform.eulerAngles = new Vector3(90, 0, 0);
}
else if(CurrentRotation.x >= 90.1f && CurrentRotation.x <= 135)
{
transform.eulerAngles = new Vector3(90, 0, 0);
}
}
}
}