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 /
  • Help Room /
avatar image
0
Question by pokitman12 · May 02, 2018 at 08:23 AM · distancepositions

Figuring out positions within a distance between two points.

Hi guys. It's kinda difficult to explain what I'm trying to achieve here but here goes.

Basically I'm trying to get the distance between two points, Get each integer within that float value and figure out the position if each integer.

In the Image I've attached, You can see there are two points set at a distance of 5. I've manually placed markers at each 1 unit along the line. It's these positions of each marker I'm trying to figure out.

So for example, in this instance, Once pointA and pointB have been positioned, A collectable object can be placed at marker 1,2,3,4 and pointB position.

I'm unsure if I'm even approaching this in the right way.

I hope I've explained this clearly. Any advice on how to approach this would be very much appreciated.

Thanks

alt text

image4161.png (37.9 kB)
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

1 Reply

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

Answer by Hellium · May 02, 2018 at 08:56 AM

I haven't tested the following script, but I think it's a good start:

 public Vector3[] GetCollectablePositions( Vector3 pointA, Vector3 pointB, float distance )
 {
     // The direction vector between A and B
     Vector3 direction = pointB - pointA ;
 
     // Get the number of collectables
     int collectableCount = Mathf.Floor( (direction.magnitude - Mathf.Epsilon )  / distance ) ;
 
     // Create the array of positions to gather all the positions
     Vector3[] collectablePositions = new Vector3[collectableCount];
 
     // Direction is now a vector separating two collectables
     direction /= collectableCount ;
 
     // Fill the array by determining the positions of the collectables according to the direction vector
     // and the position of A
     for( int collectableIndex = 0 ; collectableIndex < collectableCount ; ++collectableIndex )
     {
         collectablePositions[collectableIndex] = pointA + direction * (collectableIndex + 1)  ;
     }    
 
     return collectablePositions ;
 } 

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 pokitman12 · May 02, 2018 at 05:55 PM 0
Share

Thank you very much! After a few hours of reading into $$anonymous$$athf.Epsilon and $$anonymous$$athf.Floor as I've never used these before, I've finally got it. Thanks Again !

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

137 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 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 avatar image

Related Questions

How to get a list of the closest distance targets with NavMesh. 0 Answers

Using the Distance Bands from the CullingGroup API correctly 1 Answer

look at closer 1 Answer

How to make it so that my followAhead function doesn't active until the Gameobject moves a certain distance?,How to delay "if" statement of Camera Script after moving x distance? 1 Answer

Vector2.Distance in isometric 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