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 /
This question was closed Jan 08, 2021 at 12:15 PM by Kytheum for the following reason:

Question is off-topic or not relevant

avatar image
0
Question by Kytheum · Jan 11, 2018 at 12:06 PM · 2dphysics2ddirection

How do I get the direction of an object relative to the position and rotation of another object?

Okay, So I'm making a bunch of squares in 2D space that you can drag around and I want them to connect to each other when they are dragged into each other. So far all this system has been done but I'm running into a problem, the script cannot find which direction its connecting to upon dragging it to the object, I originally waited until collision and then Would take the two objects position to find out which side its collided with But this seems only to work while the object is aligned with the world. Is there any way to find which direction one object is relative to another?


Example, (Object 2 needs to know its just collided with the left side of object 1) alt text

Comment
Add comment · Show 1
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 dev-waqas · Jan 11, 2018 at 12:12 PM 0
Share

I think you want Transform.UP, Transform.Down etc..

1 Reply

  • Sort: 
avatar image
1
Best Answer

Answer by sisse008 · Jan 11, 2018 at 12:23 PM

each box should have 4 triggered colliders (up, down, right, left) uppon collision:

if box 2 collider with "down" collider of box 1: box2.position = box1.position - (0, box1.length/2);

if box 2 collider with "up" collider of box 1: box2.position = box1.position + (0, box1.length/2);

if box 2 collider with "left" collider of box 1: box2.position = box1.position - (box1.length/2, 0);

if box 2 collider with "right" collider of box 1: box2.position = box1.position + (box1.length/2, 0);

then, make box2 child of box 1 and make box 2 kinematik

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 Kytheum · Jan 11, 2018 at 02:10 PM 0
Share

Seemed to work well at first although the same problem appears, if box one is rotated in any way then when trying to position the cube it always ends up in the position based on the world, say I connect it to the bottom trigger and the box is rotated -90 degrees it just simply places the box on the left side. Although I think I can take the position of the 4 trigger colliders and just hand them to the second box on collision.

Follow this Question

Answers Answers and Comments

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

Related Questions

Incorrect usage of Vector3.Dot? 0 Answers

move toward but keep going 1 Answer

(2D) MovePosition slows falling 1 Answer

Get information on ignored collision 1 Answer

Attempting to add wheel friction to a 2d car 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