- Home /
How to find the direction and distance to move an object so its no longer jammed into another?
So I'm making a game where you can place objects like this cube, on other object, even slopes. So I shoot a ray at the mouse position and whatever it hits, I place the cube there and rotate it based on my raycasthit normal value. But it's kind of jammed into what its on. I don't want that. So I want to know how I can figure out the direction from the raycasthitpoint which will take the least distance to move the cube(and other shapes I might want to place) so that it no longer jammed into what I'm placing it on. And I define "jammed in" by there's an area where both colliders intersect. And btw everything is using mesh colliders(But I wouldn't mind if you told me how to figure this out if one or both of them used box or sphere or anything other than mesh colliders). And also I need a method that will work no matter the rotation of anything.
So I have a gameObject jammed into another object. They both have colliders of any type. No matter the rotation of either of them and based on information about the colliders, how do I find the direction and distance to move the gameObject so that it(it's collider) is no longer intersecting with the collider of the gameObject I'm placing it on?
Your answer
Follow this Question
Related Questions
Make sphere rotate when controlled 7 Answers
When creating joints during game play how do you change the position and rotation of an object. 0 Answers
Moving an object in a circle towards joystick 0 Answers
Quaternion to rotate a GameObject and its children 1 Answer
Control Collider Rotation independently from the object it is attached to. 1 Answer