I'm attempting to adjust the barrel of a gun up and down (to show it's going fire a further distance)
I can get it to rotate just fine, but i only want it to rotate with in a certain radius otherwise you can just keep flipping it.
this doesn't seem to work. I thought maybe the rotation would be in radians (that broke things) so i believe my math is messed up..
so this is what i want to do, have a gun that moves down when you press S and if it goes to 350 (after wrapping past 0,) it stops..
on the other side, i would like to do the opposite with W where if it goes from 350 (wrapping past 0) to 20 it stops at 20.
asked Jan 03 '12 at 08:41 PM
i've changed how i am checking my code, i'm not using a second rotation to set it, cause it's not catching it, i also threw in some variables to check for wrapping. I also built in a boolean catch to try and stop it, some time it works some times i can get past it, some times it doesn't catch it at all...
this is my full update code for it.
still could use some help on this, i'm not sure if i should use the second vector as i never caught anything with trying it.
answered Jan 04 '12 at 03:25 AM
The default rotation vector is interpreted as a quaternion, which is better for the maths but really hard to visualize. Try localEulerAngles instead, which is the XYZ rotation relative to the parent object:
You may also need to handle wrapping if the Z exceeds 360 or drops below 0, because it won't do it for you.