Home > other >  How can I find the closest flat area to the main character in Unity?
How can I find the closest flat area to the main character in Unity?

Time:07-21

Sometimes my main character gets stuck like this and if he stays in the air like this for 2-3 seconds, I want to move the main character to the nearest flat area. (The surface angle can be between 0f to 60f with a minimum 0.5f radius empty space)

How can I find the closest flat area to the main character in Unity?

Thank you so much.

enter image description here

CodePudding user response:

Raycast (or a similar method in the Physics class e.g. spherecast). From the RaycastHit get the normal of the hit and assess if it's angle is suitable using Vector3.Angle

  • Related