- Home /
Cube Rotating & Moving
Hi,
I have a simple cube that I can move left, right, up and down with the keyboard. I then wanted the cube to turn 90 degrees to flip it over in the director it is going, unfortunately it's not working as expected, and I am guessing it's me not understanding local and world coordinates.
I have a video of it so it's more clear...
http://www.youtube.com/watch?v=KPTAZgOUKCc
I read through a few articles and the Unity reference, but I can't seem to get this working as I want.
The code I use for moving and rotating are just simple methods like so...
Moving right:
function move_right(){
animating_cube = true;
var start = transform.position.x;
var y = transform.position.y;
var z = transform.position.z;
var cur : float = 0.0;
while(cur < 1.0){
cur += 0.06;
transform.position = Vector3(start - cur, y, z);
yield;
}
animating_cube = false;
}
Rotating right:
function rotate_right(){
var curRot : float = 0;
var startRot : float = transform.eulerAngles.z;
while (curRot < 90) {
curRot += 300 * Time.deltaTime;
transform.eulerAngles.z = startRot + curRot;
yield;
}
transform.eulerAngles.z = Mathf.Round(startRot + 90);
}
Any advice would be appreciated.
Thanks
Answer by Posly · Jan 20, 2012 at 09:20 PM
I would use animation so you can't mess up the rotation of the cube. I'm pretty sure you could animate that inside of unity. To do that just go to window > animation, and there's a bunch of tutorials online that can help you out.
Your answer
Follow this Question
Related Questions
Ball moving only diagonal 0 Answers
How to find cube face, to move it in that face direction 0 Answers
Moving object on plane 1 Answer