- Home /
2D top-down game. How to determine the type of surface on which the player is located and on which to click?
For example I have big collider called "Plains", on top of it collider "Forest", and on top of it collider "Lake". How to define on what surface player is standing and on what surface player clicks? What is the most simple and effective way to do that? I made some system with multiple players RigidBody, with different Z for colliders, but I think its complicated and not easy to use.
I think you could use Physics.Checksphere to detect what layer the player is standing on. For example public Layermask Grass bool OnGrass = Physics.Checksphere(groundcheck, 0.4f, Grass
would be true if the player is standing on the assigned layer 'Grass' in the inspector. The variable groundcheck is an empty GO under the player which should be the thing that detects what surface youre standing on.
Answer by varigeri92 · Aug 22, 2020 at 10:54 PM
You can Use Layers and Layermasks, so If i Understand you Correctly this Will Solve the problem.
After that you just have to cast a ray for each layer. and check them one by one
Am i standing/Clicked on Lake or Forest, or Plain...
https://docs.unity3d.com/ScriptReference/Physics2D.Raycast.html
Your answer
Follow this Question
Related Questions
Chain in 2D top down perspective. 1 Answer
AI script that follows player in a distance 1 Answer
Jumping Top Down 2D Game 0 Answers
A surface for a 2D top-down game 1 Answer