• 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 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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

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

Related Questions

How to make a 2D physical movement like this ? 0 Answers

RaycastHit2D never contains a collider 2 Answers

How to keep a gameobject on the ground ? 1 Answer

Sphere spawn from border in direction (2D) 0 Answers

Rigidbody2D is kind of flying instead of falling when the child box is colliding 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges