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
3
Question by globalenemy · Nov 20, 2016 at 12:10 PM · vector3localpositionworldpos

Local Point to World Point without TransformPoint()

Greetings,

I really would like to know, how to convert a local vector3 position to a world vector3 position. And I wanna do this without having the corresponding position on a transform. Tryed searching, but all I find is TransformPoint() and I know pretty much nothing when it comes to math. I only have two Vector3s, and creating a gameobject just to use that method seems pretty stupid. pls help me out! :)

Comment
Add comment · Show 3
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 TreyH · Nov 20, 2016 at 12:29 PM 1
Share

Well, like any coordinate conversion, it helps to know the reference frames you're dealing with.

Where the this point co$$anonymous$$g from? What is it relevant to?

avatar image globalenemy TreyH · Nov 20, 2016 at 01:15 PM 0
Share

What are you talking about? What am I missing?

There are 3 positions here. The World wich obviously is (0,0,0) a Point A that is in the world, lets say at (5,8,2) and theres a point B in Point A, lets say that one is at (4,2,9)

Now I wanna know where Point B is in the World.

avatar image TreyH TreyH · Nov 20, 2016 at 09:46 PM 0
Share

If your heirarchy is something like this:

  • Point A (5,8,2) (with child Point B (4,2,9))

Then add Point A's reference frame to Point B. Point B would be:

(4+5,8+2,2+9) --> (9,10,11)

2 Replies

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

Answer by villevli · Nov 21, 2016 at 03:00 PM

You can achieve what you want using the Matrix4x4 class.

Give a position(Vector3), rotation(Quaternion) and scale(Vector3), just like a Transform has:

 Matrix4x4 m = Matrix4x4.TRS(position, rotation, scale);

This works like Transform.TransformPoint(localPos)

 Vector3 worldPos = m.MultiplyPoint3x4(localPos); 

This works like Transform.InverseTransformPoint(worldPos)

 Vector3 localPos = m.inverse.MultiplyPoint3x4(worldPos); 

You're probably going to have rotation as Quaternion.identity and scale as Vector3.one if you only want to deal with positions.

In that case it's actually simpler to just say :

 Vector3 worldPos = localPos + position;

 Vector3 localPos = worldPos - position;

position is the same Vector3 you would have given to the Matrix4x4.TRS method. It's that simple if there's no rotation or scaling.

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 sskenth · Oct 13, 2019 at 08:48 PM 0
Share

This was really helpful, thank you for putting it together.

avatar image
-1

Answer by ToasterKyle · Nov 20, 2016 at 01:56 PM

Why do you have to convert the position from local to world space? Are the Point A and Point B parented to something? If not, simply use transform.position(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

68 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

Related Questions

Class member Vector3 based on local transform 1 Answer

localposition not working? Calculating a vector in front of an object. Picture and code included 1 Answer

Transfer axis global rotation on local axis of another object 0 Answers

Adding a local position with InverseTransformPoint works in z axis, but inverts in x axis 0 Answers

Locking gameobject to rotating floor 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