Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
2 captures
12 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 /
  • Help Room /
avatar image
2
Question by chelder · Jun 03, 2016 at 09:21 PM · scaletransform.positioncoordinatesworld coordinatestransformpoint

How to correct the scale when using Transform.TransformPoint

Let's say we have a game object named gameObjectToClone with scale Vector3(0.001,0.001,0.001). Let's say we also have a Vector3 named localPosition with the position Vector3(1,5,-3).

If we do: Vector3 worldPosition = gameObjectToClone.transform.TransformPoint (localPosition); the worldPosition will be almost the same because of such as small scale.

If we divide the worldPosition by the scale, it should give the position with the scale corrected. It seems it is not possible to divide doing Vector3 worldPositionScaled = worldPosition / scale;, so I also tried to multiply the worldPosition by 1 / scale. This multiplication is done with Vector3.Scale: Vector3 worldPositionScaled = Vector3.Scale(worldPosition, 1 / scale); Unfortunately it is not possible to perform a float / Vector3. Only Vector3 / float seems to be possible.

Is this approach correct? I guess I could divide x,y and z separately. But do you know any other approach? This one seems quite complex.

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

2 Replies

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

Answer by chelder · Jun 04, 2016 at 05:00 PM

The supposition of "If we divide the worldPosition by the scale, it should give the position with the scale corrected" is not correct.

TransformPoint seems to multiply the given Vector3 position by the transform's scale, and then adds the transform's position. To understand it better let's simplify watching only the y coordinate. Let's say we have:

 myGameObject.transform.TransformPosition(myVector3Position);

So imagine myGameObject.transform.y = 1, myVector3Position.y = 2, and myGameObject.transform.localScale = 0.001.

So TransformPosition would do before transforming to world space : 1 * 0.001 + 2. If afterwards we divide by 0.001, we would be doing something like(a) : 1 * 0.001 / 0.001 + 2 / 0.001 = 1 + 2 / 0.001 = 1.001. We don't want that! We want something like 1 + 2 = 3. My solution is to set the localScale to 1 before calling TransformPosition. After calling TransformPosition, set the orinal scale back. It would be something like the following:

 Vector3 tempOriginalScale = myGameObject.transform.localScale;
 myGameObject.transform.localScale = 1;
 myGameObject.transform.TransformPosition(myVector3Position);
 myGameObject.transform.localScale = tempOriginalScale;

(a) -> Notice it is only true if all the parent game objects (or the sum of all of them) are in the point 0,0,0 with rotation 0,0,0. However writing the example in the way I did I think can be more clear to understand the basic idea.

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
2

Answer by fanimdude32 · Sep 09, 2020 at 05:05 PM

Just use Transform.TransformDirection lol

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

60 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

Related Questions

return all models to original location (image target) 0 Answers

How to get the world coordinates of a stretched Texture2D? 0 Answers

GameObject spawning at several Y distance below my spawn point 0 Answers

Setting transform.position of the Oculus Player Controller causes it to teleport away 1 Answer

Using local coordinates on a parent object. 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