Hey all. The premise is simple: I want to adjust the X rotation of my 3D Cube to its nearest side through interpolation. So if I my cube’s X rotation is greater than 0 but lesser than 45 I want it to rotate to 0, if it is greater than 45 but lesser than 90 I want it to rotate to 90, if >90 && <135 = 90, if >135 && <180 = 180, and so on to cover all the rotation, to keep the object always in one if its sides
I’m currently using Itween to sort of “achieve this thing” (in a very buggy way). I’m using the code from below, but is not correctly working:
if(body.transform.rotation.x > 0 && body.transform.rotation.x < 46)
{
iTween.RotateTo (body, iTween.Hash ("name", "fixBodyRotation", "x", 0, "speed", fixPlayerRotationSpeed));
} else if (body.transform.rotation.x > 45 && body.transform.rotation.x < 91)
{
iTween.RotateTo (body, iTween.Hash ("name", "fixBodyRotation", "x", 90, "speed", fixPlayerRotationSpeed));
} else if (body.transform.rotation.x > 90 && body.transform.rotation.x < 136)
{
iTween.RotateTo (body, iTween.Hash ("name", "fixBodyRotation", "x", 90, "speed", fixPlayerRotationSpeed));
} else if (body.transform.rotation.x > 135 && body.transform.rotation.x < 181)
{
iTween.RotateTo (body, iTween.Hash ("name", "fixBodyRotation", "x", 180, "speed", fixPlayerRotationSpeed));
} else if (body.transform.rotation.x > 180 && body.transform.rotation.x < 226)
{
iTween.RotateTo (body, iTween.Hash ("name", "fixBodyRotation", "x", 180, "speed", fixPlayerRotationSpeed));
} else if (body.transform.rotation.x > 225 && body.transform.rotation.x < 271)
{
iTween.RotateTo (body, iTween.Hash ("name", "fixBodyRotation", "x", 270, "speed", fixPlayerRotationSpeed));
} else if (body.transform.rotation.x > 270 && body.transform.rotation.x < 316)
{
iTween.RotateTo (body, iTween.Hash ("name", "fixBodyRotation", "x", 270, "speed", fixPlayerRotationSpeed));
} else if (body.transform.rotation.x > 315 && body.transform.rotation.x < 361)
{
iTween.RotateTo (body, iTween.Hash ("name", "fixBodyRotation", "x", 359.99f, "speed", fixPlayerRotationSpeed));
}
Anyone know a better way?