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 wildpepper · Nov 08, 2011 at 05:14 PM · raycastvector3angletrigonometry

raycast and trigonometry

Hi ! I'm trying to write from scratch, a simple pathfinding/object avoidance script.

my question is, how do I calculate a Vector3 coordinate, from a given origin Vector3 (my object position) and a raycast (that doeasn't hit anything)

alt text

While of course is easy to get the raycast hit coordinates for the right ray (the one hitting the box) what i want to know, is the vector3 coordinates, of the red point, given the "observer" transform, and the left raycast direction, and a choosen max length (in this cas the red dot)

thank you for your time :)

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
1

Answer by CHPedersen · Nov 08, 2011 at 05:21 PM

You can calculate that yourself using the parametric formula for a line in space. :)

Refer to this article on parametric equations, and notice in particular the Line example. That is in fact how ray casting works, and it is the reason you need two vectors; a starting point (a0, in the article) and a direction (a1, in the article). The max length you want to go is the parameter, t.

If you have the starting point and the direction you are going in as normalized vectors, then the position of the red dot equals,

RedDot = a0 + t*a1.

As an example, let's say the bottom box is at (0,0,0), and the direction you're shooting is (-1,1,0), and you want to find the red dot at a max length of 5, then the coordinates of the dot is RedDot = (0,0,0) + 5*(-1,1,0) = (-5, 5, 0).

It's that easy. :)

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 CHPedersen · Nov 08, 2011 at 05:22 PM 0
Share

Sorry, only the direction you are going should be a normalized vector. The starting point should not.

avatar image
0

Answer by vic83 · Nov 08, 2011 at 07:03 PM

thanks ! giving it a try on it now.

I still don't know how to implement it, since the variables are of different kinds. i don't think it would simply work like that :

 RedDot.transform.position = transform.position*max_length;

anyway, giving a try right after the coffee :) thank you again, if you have further hints, go ahead :)

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Check if object is inside a viewing radius 1 Answer

Raycasting at an offset angle? 4 Answers

Angle between Ray and Normal 1 Answer

Problem With Raycasthit Angle 0 Answers

Trouble with Vector3.Angle() and RotateAround() 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