- Home /
Rotating an object - problem with angle.
Ok, I am new to coding... I made this own variation of code out of some examples and it works basically as planned = I can turn a model 120 degrees by left/right arrows (horizontally). I can also turn/tilt the model vertically but now it rotates weirdly (up/down). At "0 degrees" = not rotating the object sideways (horizontal), the vertical rotation works fine, but when I look at the model from a 120 degree angle, the up/down rotation bends sideways.
private var rotate : float = 0.0; // rotate horizontal private var rotateto : float = 0.0; // rotate horizontal private var easinout : float = 0.05; private var rotatev : float = 0.0; // rotate vertical private var rotatetov : float = 0.0; // rotate vertical var Target : GameObject;
function Update() { rotate = rotate + (rotateto - rotate) * easinout; Target.transform.rotation = Quaternion.identity;
// rotate vertical (up down) rotatev = rotatev + (rotatetov - rotatev) * easinout; Target.transform.rotation = Quaternion.identity; Target.transform.Rotate(rotatev, rotate, 0);
if (Input.GetKeyDown("left")) { rotateto += 120.0; }
if (Input.GetKeyDown("right")) { rotateto -= 120.0; }
if (Input.GetKeyDown("up")) { rotatetov += 20; }
if (Input.GetKeyDown("down")) { rotatetov -= 20; } }
I mean that the model I rotate doesnt go up/down with up/down keys, ins$$anonymous$$d it goes up/down BUT it ALSO rotates to one side. (add a camera to a level, add a capsule (and a texture) + the code above, in Inspector add the capsule as Target and run. press up/down (works fine), rotate 120 and it doesnt turn up/down the same straight way.
Answer by Velketor · Apr 16, 2011 at 12:13 AM
turn off mouselook...or at least limit the constraints of your x, y, or z values.
Answer by Tommy 1 · Apr 16, 2011 at 08:59 PM
Ok problem seems to be the object rotaes around its own axis, and not world axis. How can I get it to rotate around world axis? Adding Space.World to the end of Target.transform.Rotate(rotatev, rotate, 0, Space.World); doesnt help...
Your answer
