I’m trying to make a cube move and rotate (forward, back, right and left) using a C# script.
Still, I have a slight problem which is that I can’t change the axis on which I move my cube any time I want. I can move/rotate it forward and back, no problem. I can move/rotate it right and left, no problem. But if I move it 2 times to the left and then forward for example, the cube doesn’t move the way it should anymore.
Remember that with “transform.Up/forward/back/left/right/down” these are all relative to the object’s orientation.
The reason why your topples fail the second time… is because after the first topple, transform.up isn’t up anymore. The object might now be lying on it’s side, so transform.up might actually be pointing left…
So what does this mean? To make your rotations based on the world’s notion of up, forward, right etc… you should think in WORLD space instead of local space…
so use Vector3.up/down/right etc… instead.
This will give you the world axis in those directions… they won’t change and will always be the same no matter how many times your cube rotates.