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
0
Question by MountDoomTeam · Jan 30, 2013 at 04:53 AM · transformpoint

vertex[i] TransformPoint command not working

these are dark times at developer studio:I am making generative terrain tiles so I need to calculate the mountains on each tiles relative to their position in world space.

when I try to get the vertices world position with TransformPoint, it's still returning their local position:

Here is the code and debuglog- sampling the 1st vertex of 100 tiles, the tiles are displaced by 200, 400,etc, and their vertex TransformPoint are all the same:

 function  nzprl  (  meshobject : GameObject){//this function takes mesh objects and changes their vertices in XY and Z into mountains
 Debug.Log(  "object position   " +meshobject.transform.position  ); 
 
     var mymeshfilter : Mesh = meshobject.GetComponent(MeshFilter).mesh;
     var vtxArray : Vector3[];
     var scale = 7;
     if (vtxArray == null) vtxArray = mymeshfilter.vertices;
     var vertices = new Vector3[vtxArray.Length];
     
     for (var i=0;i<vertices.Length;i++) 
     {
         if ( i== 0 ){Debug.Log(  "vertex-position   "+vtxArray[i]  ); }
         vtxArray[i] =  transform.TransformPoint(vtxArray[i]);
         
         var vertex = vtxArray[i];
         if ( i== 0 ){Debug.Log(  "vertex-transformpoint position  "+vtxArray[i]  ); }
 
         vertex.y += (Mathf.PerlinNoise(vtxArray[i].x,5.456)*Mathf.PerlinNoise(vtxArray[i].z,7.53)-
         .5) *  scale;
 
 
         vertices[i] = transform.InverseTransformPoint(vertex);
         
     } 
     mymeshfilter.vertices = vertices;
     mymeshfilter.RecalculateNormals();
     mymeshfilter.RecalculateBounds();
     DestroyImmediate(meshobject.collider);
     meshobject.AddComponent("MeshCollider");
 
     
 }

alt text

transform problem.jpg (77.3 kB)
Comment
Add comment · Show 1
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 MountDoomTeam · Feb 02, 2013 at 05:13 PM 0
Share

this is a really weird bug!using a coroutine, I tried waiting 5 seconds after the mesh has instantiated, to access the vertices, and the transform point is still completely wrong! How can it be wrong!?

1 Reply

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

Answer by Wolfram · Feb 02, 2013 at 05:29 PM

If I understand your script correctly, your transformed tiles are in meshobject.transform, but you use the TransformPoint/InverseTransformPoint of just transform, which would be the local coordinates of the object your script is attached to, not the ones of your meshobject.

Comment
Add comment · Show 2 · 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 MountDoomTeam · Feb 02, 2013 at 05:41 PM 0
Share

Thanks, that's a lifesaver, i was just edging along the window sill as you wrote that.

avatar image drudiverse · Jul 16, 2014 at 11:09 AM 0
Share

transformpoint isnt always correct for vertices because it doesnt take into account the total size of the parent transform, if the parent transform is devided by 10, the child object vertex would still be scaled by 1... i just tried this with the correct parent and child object transform.transformpoint and the vertex position was not scaled sizewise and was falsely world space.

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

10 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

Related Questions

Transform.TransformPoint 2 Answers

TransformPoint trouble 1 Answer

TransformPoint and InverseTransformPoint: Moving Platform Logic 1 Answer

TransformPoint returns wrong points? 1 Answer

TransformPoint and InverseTransformPoint 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