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 Triqy · Jun 27, 2013 at 01:51 AM · raycastdistanceray

How to determine multiple points along a ray?

How do i determine multiple points along a ray?

Thanks-

here is my original question http://answers.unity3d.com/questions/481910/instantiate-wallfence-down-a-raycast-from-point-a.html

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

Answer by robertbu · Jun 27, 2013 at 02:02 AM

A Ray is composed of an origin and a direction. In addition, the direction is always normalized. So the best way is to use Ray.GetPoint() which will find a point a specified distance along the ray. This is equivalent to:

 var v3Pos = ray.origin + ray.direction * distance;

If you have a figurative ray (i.e. an origin and a direction but not in a Ray class instance), you can use the above formula if you make sure the direction is normalized.

Comment
Add comment · Show 5 · 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 Triqy · Jun 27, 2013 at 02:07 AM 0
Share

Im trying to get multiple points on a ray based on a distance between 2 marker points( Point A and Point B )

From $$anonymous$$arker A, i want to Shoot a ray to $$anonymous$$arker B. Then I want to Instantiate Wall Segments (10 units in width) along that ray from marker A to $$anonymous$$arker B.

avatar image Triqy · Jun 27, 2013 at 02:10 AM 0
Share

The amount of Wall segments that are needed are based on the distance i have to cover. So say a distance of 50 units, Thats 5 walls segments based on a wall segment being 10 units wide.

avatar image robertbu · Jun 27, 2013 at 02:24 AM 0
Share

This answer has four ways of moving a specific distance along a vector:

http://answers.unity3d.com/questions/478199/finding-the-direction-an-object-is-moving-and-givi.html

As for your specific problem, assume you have two Vector3 variables: v3A, and v3B that are the positions of your two objects.

You can build a ray from the two like this:

 var ray = new Ray(v3A, v3B - v3A);

And then you can use GetPoint() above to find a point at a certain distance.

Or you can do the calculations yourself:

   var origin = v3A;
   var direction = (v3B - v3A).normalized;
 
   var v3Pos = origin + direction * distance;



avatar image Triqy · Jun 27, 2013 at 02:34 AM 0
Share

So v3A and v3B are the transforms of marker A and $$anonymous$$arker B?

avatar image robertbu · Jun 27, 2013 at 02:40 AM 0
Share

v3A and v3B are the Transform.position of the two markers. If you have transforms, you can just replace v3A with trA.position and v3B with trB.position where trA and trB are the transforms of the markers.

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

15 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

Related Questions

Raycast refuses to cast down 1 Answer

How can i tell the distance from a raycast? 1 Answer

Math - calculate position in world space from ray on infinite plane 2 Answers

Bounds IntersectRay distance isnt correct 1 Answer

Unreliability of Physics.Raycast.Distance for player movement? 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