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 /
avatar image
1
Question by udk_lethal_d0se · Dec 09, 2016 at 07:33 PM · vector2positioning

How does one find the position to the left or right of an object based on the position of another?

Hello all,

I have a vessel moving towards another object at a random angle, and have an obstacle in the way at a random rotation, all in 2D space. How would I go about calculating the positions marked in red in the diagram linked below, based on the axes of the obstacle and the movement direction of the vessel?

Would I be right in thinking that a good starting point would be to get the vector from the obstacle to the vessel moving towards it by doing the following, and then creating an offset from that?

 Vector2 vesselDirFromObstacle = vessel.transform.position - obstacle.transform.position;

Please see attached diagram for further information.

alt text

office-lens-20161209-1908352.jpg (361.6 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

3 Replies

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

Answer by edcx · Dec 13, 2016 at 08:15 AM

Well, this looks like a collision avoidance problem to me. Also, you have the dir vector to the obstacle. So you can rotate that vector around z axis to get left and right vectors.

 Vector3 forward = vessel.transform.position - obstacle.transform.position;
 Vector3 left  = Quaternion.AngleAxis(90, Vector3.forward) * forward.normalized;
 Vector3 right  = Quaternion.AngleAxis(-90, Vector3.forward) * forward.normalized;

Or you can use some trigonometry to calculate.

Hope this helps.

Comment
Add comment · Show 2 · 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 udk_lethal_d0se · Dec 13, 2016 at 10:42 AM 0
Share

This is exactly what I've been looking for, thank you. I'd like to select this as the answer, but I'm unable to.

avatar image flashframe udk_lethal_d0se · Dec 13, 2016 at 11:30 AM 0
Share

Now an answer, so you can accept the solution.

avatar image
0

Answer by RobAnthem · Dec 09, 2016 at 08:05 PM

The Unity manual covers it pretty well Here

 var distance = heading.magnitude;
 var direction = heading / distance; // This is now the normalized direction.
 

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 udk_lethal_d0se · Dec 12, 2016 at 04:06 PM 0
Share

Thanks, but not quite what I'm after. Your link shows something I'm already able to do, and as stated above, I can get the vector from the obstacle to the vessel.

What I'm after is getting the up or down vector from the one that points to the vessel.

Example: If the vector pointing at the vessel from the obstacle appears to be at an angle of 225 degrees visually, I'd be looking to get the up vector which would be at an angle of 315 degrees visually.

avatar image
0

Answer by sisse008 · Dec 13, 2016 at 03:44 AM

alt text


untitled.png (11.9 kB)
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

61 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

Related Questions

Put the text on Collectibles position ! 0 Answers

Why would Vector2.Angle return wrong values 1 Answer

How to retrieve GameObject's Vector2 coordinate and move another object to it's place 1 Answer

smoothly move an object from one vector to another (crashing unity) 1 Answer

Edit Vector2 values with GUI.TextField 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