Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
11 Jun 22 - 14 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
10
Question by BirthdayBoy · Aug 05, 2015 at 03:56 AM · transformvector3difference

Difference Between Transform.TransformVector and Transform.TransformPoint

My confusion arose in the following scenario:

 transform a;
 transform b;
 
 Vector3 newPosition = NewLocalPosition(a);
 b.position = a.TransformPoint(newPosition);
 
 void NewLocalPosition(transform){
    based on some input ;
    return new local position of transform ;
 }

Transform a was descendant of many parents and transform b had no parents.

I was attempting to set the global position of transform b to the global position equivalent of the calculated new local position of transform a. I had only used TransformPoint in the past and this was giving me unwanted results. After a few hours of fiddling around i realized that TransformVector gave me the results i was looking for. I dont really understand why one works and not the other.

I would really appreciate some clarity in what the difference is as I am unable to find a clear explanation anywhere. Thankyou.

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
43

Answer by zach-r-d · Aug 05, 2015 at 11:05 AM

There are three similar methods on transform: TransformPoint, TransformDirection, and TransformVector. The difference comes down to which aspects of the transform are used or not used when performing the transform:

  • TransformPoint: position, rotation, and scale

  • TransformDirection: rotation only

  • TransformVector: rotation and scale only

TransformPoint is used, as the name implies to transform a point from local space to global space. For example, if the collider of a player is offset by half their height so that the transform position is at the player's feet, to get the world space position of the collider center, it would be playerTransform.TransformPoint(collider.center) because that world-space position will change if any one of the player's position, rotation, or scale changes.

TransformDirection is used to transform a direction. For example, if there were a friendly AI that always wanted to face the same direction as the player, it would set its rotation to Quaternion.LookDirection(playerTransform.TransformDirection(Vector3.forward)). There's actually a convenience property on transform called .forward that does exactly this, but bear with me. This rotates Vector3.forward (which is 0,0,1) to face the direction of the player's forward direction. So if the player's rotation is in the default orientation, it will just return 0,0,1. But if the player were looking straight down, it would return 0,-1,0. Since TransformDirection only cares about the rotation, note that the magnitude is preserved.

And finally, there's TransformVector, which seems to be the same as TransformDirection, but takes scale into account and will thus change the return value's magnitude accordingly (and probably the direction too if the scale is nonuniform). I'm not actually sure what this is useful for, since my use cases always fall under the first two, but clearly you've found a use for it!

Comment
Add comment · Show 4 · 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 BirthdayBoy · Aug 05, 2015 at 04:20 PM 1
Share

Great description of point and direction but those are already clear to me. From what my results and the little bit on the internet is telling me that TransformVector is closer to TransformPoint than TransformDirection. Has nobody ever used TransformVector?

avatar image zach-r-d · Aug 05, 2015 at 07:08 PM 0
Share

Sure, it's equally valid to think of TransformVector as TransformPoint ignoring position as TransformDirection but scale-aware.

I can't find any discussion of TransformVector usage online. It could be that when TransformVector would be useful, people tend to use TransformPoint or TransformDirection and then subtract or add transform.position manually.

avatar image kilomotor · Jan 17, 2017 at 02:24 AM 0
Share

Thank you for the summary of Point vs Direction vs Vector. This was very helpful and allowed me to finally figure out what was going wrong with a raycast.

avatar image tony_dreamcraft · Jun 29, 2018 at 03:57 PM 4
Share

For people finding this later and still don't see a use for TransformVector after reading this, it is used for transfor$$anonymous$$g things like velocities, accelerations, momentum. In other words, vector quantities. The main reason there are different methods for TransformPoint and TransformVector is so it can decide what to do when multiplying a Vector3 by a $$anonymous$$atrix4x4. For TransformPoint the conversion from Vector3 to Vector4 is (x,y,z,1) and TransformVector it is (x,y,z,0). For TransformDirection you conjugate (x,y,z,0) by the rotation quaternion (I'm not sure that this is exactly what Unity does, but conceptually that is what is happening).

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

6 People are following this question.

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

Related Questions

Vector3 sets to different coordinates than specified 1 Answer

Moving by rotation of objects 0 Answers

Get the Vector position of the player object when clicking another object C# 1 Answer

Moving a Platform 1 Answer

Why using = isn´t fast enough for changing Vector3 values from the transform? 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