- Home /
How do I find the closest point on a specific side of a bounding box?
I am trying to 'draw' an object between two points. This is working fine, but I would like the objects start/end positions to be the furthest right and left, respectively, of the objects that they are drawn between.
Answer by IvovdMarel · Aug 14, 2017 at 03:34 AM
You should look at
https://docs.unity3d.com/ScriptReference/Collider.ClosestPointOnBounds.html
or just
https://docs.unity3d.com/ScriptReference/Bounds.ClosestPoint.html
Answer by BiffJenkins · Aug 14, 2017 at 03:59 AM
Hi @IvovdMarel,
Thanks so much for your response. I was looking at this, but haven't been able to get it to work in my particular scenario.
I have a cube and I cast a ray hitting the front of it. I now need to know where the corresponding vector3 is it on the right side of the cube.
Hi BiffJenkins, so is this 'Desired Vector3' point always at the exact same position relative to the object? In that case you could create a child-transform or set a standard offset.
Or, is it relative to the position that was hit? And if so, how is it relative? Perhaps explaining your full intention would be easier.
It is relative to the position that was hit. I am essentially trying to "draw" a bridge between two points by instantiating a GameObject. The player can click anywhere on valid game objects which I check with a Raycast hit and tag. A valid mouse click down instantiates the bridge object which scales towards their mouse while holding down click. When mouse click up on another valid game object, the bridge object is 'finalized'. If they let go of click on an object that isn't valid, the bridge they were 'drawing' is destroyed.
I am using 3d objects specifically for lighting, but it is a 2d game. I need the bridge to be as short as possible because I will be checking collisions for later gameplay.
Answer by Damiano96 · Jul 23, 2020 at 08:10 AM
Hello @BiffJenkins, im working on something similiar, did you ever find a way to solve your problem? Thankyou!
Your answer
Follow this Question
Related Questions
Raycasts in opposite directions only returning RaycastHits on right 1 Answer
Wall Running using Javascript 0 Answers
Rigidbody object intersection 0 Answers