I want to rotate my player in the way I showed in the picture. I don't understand what Vector3. I would use here in transform.rotate
1 Answer
As we talked in comments I guess that you know what Vectors are from your background.
And with transform.rotate()
there are more then one options to use that method which we call Method Overloading. And one of the way to use is that is transform.Rotate(Vector3 direction, float rotation)
.
And the reason it takes Vector3
as a direction in this method is because the way Unity handles direction.
In Unity as when it comes to direction with Vector3
it is considered/calculated as follows
Vector3.right = x = 1, y = 0, z = 0
Vector3.left = x = -1, y = 0, z = 0
Vector3.up = x = 0, y = 1, z = 0
Vector3.down = x = 0, y = -1, z = 0
Vector3.forward = x = 0, y = 0, z = 1
Vector3.back = x = 0, y = 0, z = -1
So to answering your question you can achieve the functionality by using Vector3.forword
as direction. Because the direction/Axis you want your object to be rotated is the one from back
to front
if you consider Vector3
that would be z axis ans as I've listed above you can use Vector3.forward
as a direction/axis of your rotation in transform.Rotate()
Reference:
Tranform.Rotate
Hope this helps, welcome to unity Happy Coding
-
2Helpful info but you should probably include your comment's "
Vector3.forward
" in the answer somewhere ;)– RuzihmAug 16, 2020 at 17:44
Vector3.forward
This should work