The question is answered, right answer was accepted
How rotate diagonally a cube
Hi, i'm a beginner. How can i rotate my cube diagonally?
Answer by hexagonius · Jan 16, 2016 at 01:18 PM
Rotation always happens around an axis. usually you rotate around x, y or z axis. In your case, you use a diagonal axis like
new Vector3(1,1,1);
which points into the upper forward right corner. Use it like this:
transform.Rotate(Vector3.one * Time.deltaTime);
where Vector3.one is shorthand for a Vector3(1,1,1);
Rotate has a last default parameter which is set to Space.Self, which means it does not matter how the cube is rotated in the first place, the rotation stays the same relative to that cube.
thanks @hexagonius for the comment but i don't understand, here is my code private Vector3 V = new Vector3(10, 10, 10); void Update() { transform.Rotate(V * Time.deltaTime);}
but the cube does not rotate diagonally
And what is it doing? I mean the rotation is not spot on perfect, but in my scene it IS rotating diagonally (C# though):
using UnityEngine;
using System.Collections;
public class Rotator : $$anonymous$$onoBehaviour {
Vector3 V = new Vector3(10,10,10);
// Update is called once per frame
void Update () {
transform.Rotate(V * Time.deltaTime);
}
}
@hexagonius i'm sorry but this is not what i mean;
this is my cube and i want that his rotation is only on the diagonal of the square! I'm sorry if i can't explain very well! :)
Follow this Question
Related Questions
vector3 rotatetowards don't work 1 Answer
angle add constant at vector3 1 Answer
Roatate object to player on tag 0 Answers
How to Rotate on Y Axis by 90 degrees left or right? 1 Answer
it is possible to rotate a texture ? 0 Answers