- Home /
Object wont rotate in the opposite direction
I wrote a rotation script:
{
{
if (targetSpeed < -1)
{
transform.eulerAngles = Vector3.up * 45;
} else {
transform.eulerAngles = Vector3.up;
}
}
{
if (targetSpeed > 1)
{
transform.eulerAngles = Vector3.up * -45;
} else {
transform.eulerAngles = Vector3.up;
}
}
}
The object will rotate to the right (from my perspective) and follows the targetSpeed > 1 rule, but doesnt not follow the targetSpeed < -1 rule.
Any suggestions as to what might be causing this? I know its probably a pretty simple solution but a fresh pair of eyes would be welcome!
Answer by poncho · May 02, 2014 at 03:59 PM
if you are trying to make it work using values as between -1 and 1, -1 and 1 included it wont move, change the value of rotation to see if it is moving but the simetry of the object does not allows you to see it, try including the -1 and 1 to the equation, try changing the = for += to make the value move with each update, keep trying.
if (targetSpeed <= -1)
transform.eulerAngles = Vector3.up * 45;
else
transform.eulerAngles = Vector3.up;
if (targetSpeed >= 1)
transform.eulerAngles = Vector3.up * -45;
else
transform.eulerAngles = Vector3.up;
btw, "{" "}" signs are used to sepparate multiple lines, with only 1 line in the if, they are not needed, it makes it more legible, but sometimes people put some extra {} and never find where the mistake was, so keep these guys minimum
good luck