Home > Enterprise >  Prototype 1 Challenge in Unity
Prototype 1 Challenge in Unity

Time:08-31

Plane flying on z-axis

I'm slightly confused with the transform.Rotate on this challenge.

I have the plane moving on the z axis horizontally using left/right keys. However, in the tut it says use "up" to operate the vertical using: "transform.Rotate(Vector3.up, rotationSpeed * verticalInput * Time.deltaTime);"

But up just rotates the plane round the y axis so I used "right" instead: transform.Rotate(Vector3.right, rotationSpeed * verticalInput * Time.deltaTime);

Can someone please explain why "up" will not work?

CodePudding user response:

In your case, it seems to be Vector3.Right (1,0,0) because your moving along the z-axis for your horizontal movement (actually, the x-axis would be preferable here, if your movement is kept 2D overall as "horizontal" in 2D is along x-axis usually). Z-axis is usually depth.

Transform.Rotate(Vector3 axis, float angle, Space relativeTo = Space.Self)

always rotates around the axis given as if the axis were the pole around which to rotate and in default uses the local coordinate system of the object. So in your case, Vector3.Right actually points towards you (out of the screen) from the local transform of the plane and rotating around this axis tilts the planes nose so to say.

It's a bit fiddly to explain transform rotations but I hope this helps.

  • Related