- Home /
Find closest point on all objects in a layermask
Hello All :)
I'm trying to make a 3D version of the game i have in this link:
I use C#
Essentially, i am trying to make a game where a player walks on strange 3D shapes. to accomplish this, i want to make a gravity code that finds the closest point on all coliders within a LayerMask to apply a force towards. Simple enough right?
My problem arises in finding said point. Ive tried Spherecasting to no avail. probably just doing it wrong.
If anyone could find me a code where I give an int variable and it creates a sphere of Vector 3 Positions around an object (amount of positions based on the int).
or If there is a raycast method that returns the closest point of all colliders in a layermask.
It would be extremely helpful :)
Thank You!
Answer by Ermiq · Aug 27, 2018 at 08:48 PM
Seems like 'collider.ClosestPointOnBounds' does what you need: https://docs.unity3d.com/ru/530/ScriptReference/Collider.ClosestPointOnBounds.html
Your answer
Follow this Question
Related Questions
Physics.Boxcast not working with mesh collider 1 Answer
Adaptive Mesh 1 Answer
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
How to make a system that will let elements interact with other elements? 1 Answer