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 GTHell · May 06, 2017 at 12:21 AM · camera3rd person camerarelative movement

How does TransformDirection(Vector) work?

I have this line of Code:

//dir variable is vector3 declare at the top

//input() is Vector3 function that return input from Key

 dir = Camera.Main.TransformDirection(input());
 rigidbody.AddForce((moveVector * 10f));

The function is transform direction from Local to World space and the Document is very scarce on what is it return. In this case, we use TransformDirection on Camera component and take input(), which is return World Space vector3, as argument.

What I want to know is does it take the input() and turn it into Camera.Main world direction or vice versa?

Comment
Add comment · Show 4
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 RobAnthem · May 06, 2017 at 04:35 AM 1
Share

Local vs World space:

Local space exists within the objects localized confinement, being that if the object is parented to another object, then the child is now contained with in local space.

World space is the ACTUAL representation of the objects spaces in the entire 3D world, of course based on the originally deter$$anonymous$$ed 0,0,0 of starting space.

Now what TransformDirection does, is it takes a direction from LOCAL and converts it into WORLD, meaning that if an object is facing north, and it's parent is facing south, then the objects World direction is south. If you convert its local direction though, you will find it is actually facing north.

I hope this helped clarify.

Also, if you attempt to use TransformDirection on an object that has no parent, it will return the exact same as the direction that was input. So to clarify, It is best used like this.

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


The documentation is actually quite clear on what this does. It just assumes you already read up on local and world space.

avatar image GTHell RobAnthem · May 06, 2017 at 03:25 PM 0
Share

Does it mean

 Camera.$$anonymous$$ain.TransformDirection(input());
 transform.TransformDirection(input());

is indeed the same?

or the Camera.$$anonymous$$ain become the parent of the input() then it does the Local/World transformation?

avatar image RobAnthem GTHell · May 06, 2017 at 04:34 PM 0
Share

Correct, it won't make any difference unless you are actually using the camera as your point, like this.

 Vector3 dir = transform.TransformDirection(Camera.$$anonymous$$ain.transform.forward);

It is a function built into Transform, so any object with a Transform will have the TransformDirection option. Does not matter how you run it, the input/output is the relevant part.

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Kishotta · May 06, 2017 at 05:49 PM

The idea behind TransformDirection is to take a a vector in local space and convert it to world space. Take some randomly rotated object. It's "forward" direction is ALWAYS <0, 0, 1> in local space. However, if it's rotated 45 degrees about the global Y axis, for example, that same forward vector might look like <0.52, 0, 0.52> in world space.

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

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

96 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 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

Rotate 3rd person camera around player 1 Answer

Advanced Camera Rotation 1 Answer

Rotate 3rd person camera around player 0 Answers

Moving player in direciton camera is facing 1 Answer

Modifying Cinemachine values during runtime 1 Answer


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