- Home /
Question by
InDeedNot · Apr 01, 2018 at 01:42 PM ·
vector3rotation axistransform.rotate
Vector3 - Rotate a cube by its spatial (longer) diagonal
I'm following the Roll a ball tutorial, and I've reached the part when the pickup object (cube) is tilted. Since I want the spatial (larger) diagonal of the cube to be pointing straight up (globally), I've tilted / rotated the cube like so: x = 35° y = 0 z = 45°
What values should I use in this:
void Update() {
transform.Rotate(new Vector3(x,y,z) * Time.deltaTime);
}
so that the cube rotates around its spatial diagonal? In case it's not clear what I'm asking. I want to achieve this kind of rotation (minus the wiggling):
Is this even possible to do with one line of code?
Comment
Best Answer
Answer by InDeedNot · Apr 01, 2018 at 02:08 PM
Should've read the documentation more carefully. Space.World
is what I needed. With that, my code becomes
void Update() {
transform.Rotate(new Vector3(0,90,0), Space.World);
}