Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Matthew_Crown · Jul 10, 2013 at 04:33 PM · rotationrotations

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))
         {
             transform.Rotate(0,m_speed*Time.deltaTime,0);
         }
         
         if (Input.GetKey(KeyCode.A))
         {
             transform.Rotate(0,-m_speed*Time.deltaTime,0);
         
         }    
             if (Input.GetKey(KeyCode.W))
         {
         Vector3 fwd = new Vector3(0,0,1);
                 m_airplane.AddForce(fwd*20);
         }
     
     }
 }
 

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

best regards!

matthew

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Kiloblargh · Jul 10, 2013 at 04:37 PM

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Matthew_Crown · Jul 10, 2013 at 05:13 PM

thanks,

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! :)

matt

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Alnos · Jan 07, 2020 at 11:31 AM

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?

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image unity_vrr-wqcRdjb5zQ · May 22, 2021 at 04:26 AM 0
Share

@Alnos

transform.localPosition.z;

might be the line that you're looking for :)

to set localPosition to new vector write:

transform.localPostion = new Vector3(X, Y, Z);

or you can access an axis separately by adding the .x, .y, or .z at the end hope that helps if you haven't already found the answer.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

17 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Positions to rotations of a regular GO 2 Answers

How to use quaternions to apply an offset to a rotation to calibrate a controller 1 Answer

Programming Accurate Clock Hands 1 Answer

How can i limit rotation in my script? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges