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
1
Question by urg0tt · Sep 17, 2012 at 09:06 AM · vector3anglecalculatetriangle

How to calculate a Vector3 point having three given Vector3 points and an angle of 90 degrees?

Hello together!

I'm currently implementing an obstacle avoidance system. I have my main character (1), a small obstacle (2) and the desired destination (3).

Trying to move my character to the desired destination results in detecting the obstacle within its range. Now i want to send the obstacle away to make way for the character.

I am casting two rays (yellow) outside character's range (blue) with the additional range of the obstacle's radius.

I would like to start checking valid positions for the obstacle at point 4 - let's call it position x on the left ray. If this point isn't valid cause of another kind of obstacle at this place, I will check the same position on the other ray. If this position is false too, I would like to increase the position x to x+1 and check again.

To get a ray point I could easily make use of:

 Ray ray;
 ray.GetPoint(float distance);

But to start exactly at point 4 I need to get the distance from character's position to the white arrow on the green line somehow.

So how can I calculate this specific distance or at least the point where the white arrow is pointing to?

alt text

unbenannt.png (103.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
0
Best Answer

Answer by Zerot · Sep 17, 2012 at 11:43 AM

If I understand it correctly, you want the point which is the projected point of the obstacle point onto the green line.

Unity has a function for that: http://docs.unity3d.com/Documentation/ScriptReference/Vector3.Project.html

You could also calculate it yourself using the dotproduct.

Comment
Add comment · Show 4 · 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 urg0tt · Sep 17, 2012 at 01:44 PM 0
Share

Thank you for your reply.

This sounds quite interesting, but I don't know how to get it work. I've tried something like this:

// Start

Vector3 toDestination = characterDestination - characterPosition;

Vector3 toDestinationNormalized = Vector3.Normalize(toDestination);

Vector3 toObstacle = obstaclePosition - characterPosition;

Vector3 projectedPoint = characterPosition + toDestinationNormalized * Vector3.Dot(characterPosition, toObstacle);

Vector3 projectedPointUnity = Vector3.Project(toDestination, obstaclePosition);

// End

But the resulting point is definitely not on the straight direction line.

avatar image Zerot · Sep 17, 2012 at 02:27 PM 0
Share

well, that is because you are using it incorrectly ;)

Vector3 projectedPointUnity = characterPosition + Vector3.Project(toObstacle, toDestinationNormalized);

This should give you the correct position(have not tested it, so might contain typos)

avatar image fafase · Sep 18, 2012 at 05:14 AM 0
Share

Yes, that would work but it seems you are still missing the value for toObstacle. I do not see where you get this one from.

avatar image urg0tt · Sep 18, 2012 at 08:53 AM 0
Share

Ok. I don't know why, but I've tried it yesterday and it didn't work and now I write the same code again and it does. There must have been a stupid little mistake in just a few code lines. Funny. So your solution works perfectly for me right now. Thank you both for helping me!

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

13 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

Related Questions

How do you calculate the rotation of a hexagon based on the six Vector3 points 0 Answers

change angle of vector3 0 Answers

Angle between two vector3 relative to a certain point 1 Answer

Find Vector3 from a starting Vector3, angle, and distance. 1 Answer

Average of Normals 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