z axis doesn't follow the rotation of its object

hello guys,
strange problem this time.
in myscene I want to pilot an airplane but I get some issues doing that.
The problem is this:

when I rotate the airplane, its z axis (forward direction) don’t rotate with it, as shown in the image below.

alt text

with D button and Abutton I rotate clockwise and counterclockwise, but Z are always facing z world.
This is bad expecially when I add a force to my airplane, trying to drive it where I want.
The result is that I rotate the plane but it continues to go straight, aiming the z world axis and not its front nose.

here u are the script:

using UnityEngine;
using System.Collections;

public class NewBehaviourScript : MonoBehaviour {
	    public float m_speed = 4.0f;
	    public Rigidbody m_airplane = null; //I put here the mesh of the airplane, the same object assigned to this script
	// Use this for initialization
	void Start () {
	// Update is called once per frame
	void Update () {
		if (Input.GetKey(KeyCode.D))
		if (Input.GetKey(KeyCode.A))
			if (Input.GetKey(KeyCode.W))
		Vector3 fwd = new Vector3(0,0,1);

some one could help me to solve this mistery, please?

best regards!


In the top left of the editor window, press the button that says Global so that it says Local instead. This will fix your axis display.

Then in your code, you created a Vector3 called fwd, but you did not set it to the airplane’s transform.forward. So you are telling it to add force in the global Z direction, not the forward direction, and Unity’s just doing what you told it.


I changed the fwd vector3 inthis way:

Vector3 fwd = m_airplane.transform.forward;	

but the problem remain the same. could u suggest me the right script in order to make it working, please?

The localrotation now are visible! :slight_smile:


Hey guys I have the same problem here so what’s the script line I’m missing to use the local z axis instead of the world z axis?