Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
2
Question by fulcanmal · Oct 03, 2010 at 12:49 AM · worldspacetransformpoint

Transform.TransformPoint

In the Unity API it describes TransformPoint as follows:

Transforms position from local space to world space.

Then it lists the following example code:

    // You need to assign an object to this variable in the inspector
var someObject : GameObject;
// Instantiate an object to the right of the current object
thePosition = transform.TransformPoint(2, 0, 0);
Instantiate(someObject, thePosition);

But if TransformPoint converts local coordinates to world coordinates, then how would this instantiate to the right of the game object, and not simply 2 units to the right of the World Space origin?

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
4
Best Answer

Answer by Jesse Anders · Oct 03, 2010 at 01:17 AM

I'm not sure if I understand your question fully, but it's exactly because TransformPoint() converts from local coordinates to world coordinates that the new object is spawned to the right of the current object.

Let's say that if you hold your right arm straight out to the side, the local-space coordinate (2, 0, 0) is at the tips of your fingers. No matter where you go or how you orient yourself, as long as you keep your arm straight out, the tips of your fingers will still be at exactly the same location in local space.

However, as you move and re-orient yourself, the world-space position of the tips of your fingers is constantly changing. This is what TransformPoint() does; it takes the local-space coordinate ((2, 0, 0) in this case) and converts it to a world-space coordinate based on the current transform for the object (the object being you in our example).

I don't know if that clears things up at all, but basically, what's described in the example you posted is indeed the expected (and correct) behavior.

Comment
Add comment · Show 6 · 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 Loius · Oct 03, 2010 at 01:09 AM 2
Share

It's converting the local point (2,0,0) to the world point (t.x+2, t.y+0, t.z+0), where t = the transform.

avatar image Jesse Anders · Oct 03, 2010 at 01:25 AM 1
Share

That's not what TransformPoint() does, generally speaking. If the transform happens to incorporate translation only, the end result would be as in your example, but in most cases other transformations (such as rotation and scale) will be involved as well.

avatar image fulcanmal · Oct 03, 2010 at 01:44 AM 0
Share

Ah I see, it was more a misunderstanding of how they presented it on my part. So if I understand you correctly, and we instantiate an object at (2,0,0) in local space, but then the game object rotates 90degrees left, then we repeat the same process by instantiating again at (2,0,0), it will instantiate in a separate location (still to the right of the game object, but relative to the game objects rotation)

If we instantiate in world coordinates, that object will instantiate to the right of the object, but in the same position regardless of the game objects rotation. Correct?

avatar image Jesse Anders · Oct 03, 2010 at 01:07 PM 0
Share

Yes, that sounds right :)

avatar image fulcanmal · Oct 03, 2010 at 08:52 PM 0
Share

Thank you, sir!

Show more comments
avatar image
1

Answer by lilinjie_ · Apr 20, 2018 at 07:48 AM

I think the description of the Unity manual is not detail. Transform.TransformPoint transforms position from local space to world space which the position is based on the transform local space. That's mean the position is relative to the current transform local space (the current transform is the origin point of the position).

 using UnityEngine;
     using System.Collections;
     
     public class ExampleClass : MonoBehaviour
     {
         public GameObject someObject;
         public Vector3 thePosition;
     
         void Start()
         {
             // Instantiate an object to the right of the current object
             thePosition = transform.TransformPoint(Vector3.right * 2);
             Instantiate(someObject, thePosition, someObject.transform.rotation);
         }
     }
 

So the above example is mean convert the position 2 units right from the current transform in local space to world space then instantiate the clone at that position. So the new clone is always at the 2 units right from the current transform in local space.

Through the manual someone may think transform.TransformPoint(2, 0, 0) mean the position(2, 0, 0) in transform local space, but it is mean 2 units right from the current transform in local space. So the clone is not always at the position(2, 0, 0) in local space, but at the position 2 units right from the current transform in local space.

You can try this example may be help:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 // Create Empty GameObject as the parent, change the transform anything but not the Vector3.zero
 // Create a Cube as the someObject and attach the script to it
 public class TransformPointExample : MonoBehaviour {
     public GameObject someObject;
     public Transform parent;
     public Vector3 thePosition;
     private void Start()
     {
         string log = "";
         log = "Current Transform World Space# " + transform.position + ", Current Transform Local Space# " + transform.localPosition + ", Point# " + (Vector3.right * 2).ToString() + "\r\n";
         thePosition = transform.TransformPoint(Vector3.right * 2);
         GameObject clone = Instantiate(someObject, thePosition, someObject.transform.rotation);
         clone.transform.SetParent(parent);
         log += "thePosition# " + thePosition + ", Current Transform Inverse Transform# " + transform.InverseTransformPoint(thePosition);
         transform.localPosition = Vector3.zero;
         log += ", local position Vector3.zero Transform Inverse Transform# " + transform.InverseTransformPoint(thePosition);
         Debug.Log(log);
     }
 }




alt text


exampleoutput.jpg (128.4 kB)
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

2 People are following this question.

avatar image avatar image

Related Questions

Is there an end to Unity world space? 3 Answers

Lerp a Child but 'keep up locally' with Parent 0 Answers

How do I make a UI element in world space cover a game object in the scene? 0 Answers

[Solved] Translating Camera on only X, Z axis on World Space, no matter what is the rotation 0 Answers

Interacting with a world space GUI in VR 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