1

rotate

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

5
  • Sorry, but just want to make sure that i'm getting it right. So What you are asking What Vector3 is right? Aug 16, 2020 at 15:24
  • I guess that I have an answer for your question but I just want to confirm that what i understood is what you are asking. Aug 16, 2020 at 15:25
  • yeah, Vector3.up, right are working (because they are not the direction I want), I think there should be a type of rotation for that
    – MAN-MADE
    Aug 16, 2020 at 15:52
  • 2
    try using Vector3.forward This should work Aug 16, 2020 at 15:55
  • I'm Adding an answer explaining why this is working, so that you and other can understand. Aug 16, 2020 at 16:02

1 Answer 1

2

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

1
  • 2
    Helpful info but you should probably include your comment's "Vector3.forward" in the answer somewhere ;)
    – Ruzihm
    Aug 16, 2020 at 17:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.