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 Orzel · May 14, 2014 at 10:52 PM · directionvectorpointmove to

Move point in the direction of another

Hello there, guys!

I have a question... I've got cube for example, it's have 8 verts and him transform.position point is center inside.

I want to move every vert in direction of central point but in random distance. My thinking assumed st like that:

 mesh = //here component of cube's mesh
 for(var vert in verts)
 {
    var direction : Vector3 = vert - cube.transform.position;
    direction = direction.normalize;
    vert += direction * RandomDistance;
 }

But don't know why it's calculate wrong direction... As result it's move every vert to wrong direction. I have no idea what should I do... Any help?

Regards.

Comment
Add comment · Show 6
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 rutter · May 14, 2014 at 11:03 PM 0
Share

Need more information. What did you expect would happen? What actually happened that wasn't supposed to?

avatar image Orzel · May 15, 2014 at 07:25 AM 0
Share

Well, vert is moving, so that's ok, but in some other direction. Always in the same, I mean not random for every vert. They aren't going to center of cube and not to the 0,0,0 point. I don't really know how to define their direction because it's calculate wrong so...

avatar image Orzel · May 15, 2014 at 09:52 AM 0
Share

I wanna bump it up cuuz didn't inv anything?

avatar image AlucardJay · May 15, 2014 at 11:12 AM 1
Share

The vertex points are in local-space, but the cube position is is world-space.

 for(var vert in verts)
 {
     var direction : Vector3 = vert;
     direction = direction.Normalized();
     vert += direction * RandomDistance;
 }

If you want to use the cube as a reference :

 var direction : Vector3 = cube.transform.position - transform.position;
avatar image Orzel · May 15, 2014 at 05:00 PM 0
Share

No - it's not answer alucardj, cuz I tried

    cube.position - vert
    cube.position - transform.TransformPoint(vert)
    vert - cube.position
    transform.TransformPoint(vert) - cube.position

End all of those badly calculate this damn direction.

Show more comments

1 Reply

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

Answer by Orzel · May 15, 2014 at 05:37 PM

I did it on my own. With regards for everyone who has the same problem:

 direction = Target.transform.position - transform.TransformPoint(vert);
 direction = moveDir.normalized;
 vert = transform.InverseTransformPoint(transform.TransformPoint(vert) + (direction * distance));
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 robertbu · May 15, 2014 at 05:42 PM 0
Share

Your code here is taking the long way around. There is no need for most of it and @alucardj's example is correct, and your 'direction' will be 'vert'. Here is a concrete example. Say your vert is (1,1,1), and your target.transform.position is (2,2,2). This means that the world position of the vert would be (3,3,3). So your calculation first converts (1,1,1) to (3,3,3) using Transform.Point(), then subtracts (2,2,2) to get back to (1,1,1). If you don't believe me, do:

 Debug.Log(direction + ", " + vert);

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

22 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

Related Questions

Vector direction to point 1 Answer

Finding the difference between two directions? 0 Answers

How to fix/clamp rigidbody dir vector, despite Force dir 1 Answer

"normalize" a vector but conserve the "- sign" 2 Answers

Clamp Vector direction to one axis 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