Find closest point on all objects in a layermask

Hello All :slight_smile:

I’m trying to make a 3D version of the game i have in this link:

Demons

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 :slight_smile:

Thank You!

Seems like ‘collider.ClosestPointOnBounds’ does what you need: Unity - API скриптов: Collider.ClosestPointOnBounds