Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 kkrac · Nov 07, 2017 at 01:58 AM · transformdirection

transform.TransformDirection(transform.forward) (0.0, 0.0, -1.0)

With the gameobject's forward vector pointing to global positive x...

  1. transform.TransformDirection(Vector3.forward) outputs (1.0, 0.0, 0.0) ... OK, understood.

  2. transform.TransformDirection(transform.forward) outputs (0.0, 0.0, -1.0) .... Why?

Can someone explain why #2?

alt text

transform.png (61.1 kB)
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

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by Bunny83 · Nov 07, 2017 at 02:04 AM

This line of code makes no sense. "TransformDirection" takes a local space direction vector as input. transform.forward is a worldspace direction.

Basically Those two lines are identical:

 Vector3 fwd = transform.forward;
 
 Vector3 fwd = transform.TransformDirection(Vector3.forward);

Your code does interprets a worldspace direction as localspace direction and transforms it again. The result will be nonsense.

So this line:

     transform.TransformDirection(transform.forward);

would be the same as doing

     transform.TransformDirection(transform.TransformDirection(Vector3.forward));
Comment
Add comment · Show 3 · 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 Bunny83 · Nov 07, 2017 at 02:09 AM 0
Share

Just to clarify / explain the result of (0, 0, -1):

Vector3.forward is just the constant (0,0,1). Your gameobject is rotated 90° to the right. So everything in localspace is rotated 90° clockwise. "transform.forward" is the worldspace forward direction of your object which is in your case (1,0,0). If you treat this as localspace direction (so within the localspace it points to the "right" of the object's own rotation) and transform it again into world space (effectively rotating it 90° clockwise) you end up at (0,0,-1)

avatar image kkrac Bunny83 · Jan 11, 2018 at 04:49 PM 0
Share

Came back to this post and realized I have one more question, for the same example above:

Why does transform.InverseTransformDirection(Vector3.forward) return (-1.0, 0.0, 0.0) ?

And if the rotation is the opposite of the example (ie: -90) it returns (1, 0, 0)

I was expecting it to be the other way round: (1, 0, 0) when the object was looking to the positive X global axis

avatar image Bunny83 kkrac · Jan 11, 2018 at 05:14 PM 0
Share

InverseTransformDirection transforms a worldspace direction into a localspace direction. If your object is rotated 90° to the right (cliockwise when viewed from above) the objects's x-axis (the red one) will point along the negative world z direction. So it points in the opposite direction of the world z axis (the blue one).


Of course when you have a worldspace direction of (0,0,1) it will come out as local space direction (-1, 0, 0).


If you rotate the object counter clockwise 90° the objects local x axis will be aligned with the world space z axis. That's why in this case the worldspace (0,0,1) direction will come out as (1,0,0)

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

72 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 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 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 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 avatar image avatar image avatar image avatar image

Related Questions

Using TransformDirection incorrectly? 2 Answers

How should TransformDirection be used? 1 Answer

Gyroscope.attitude = GetComponent ().TransformDirection ? 1 Answer

Help understand moveDirection = transform.TransformDirection(moveDirection); 1 Answer

How to have correct strafe animation based on the players rotation? 2 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