C# 2D Top down game how to detect if objects are touching while they can pass through each other?
Hello,
i have my top down game map and it has some water in it, i want the player to switch to swimming mode when hes on water, for now there is just the map which is generated with tiles of dirt and water, and the player which has nothing connected to the map, how do i do it? plz help, in c# if possible.
Answer by Ali-hatem · Mar 31, 2016 at 12:14 PM
you can make a saprate image to water & add a box collider to it & make it is trigger & tag it & box collider to player then in player script :
void OnTriggerEnter2D(Collider2D other) {
if(other.tag == "water")
// swwim
}
but if you don't want that you have to cheek the player position if it inside the water position which is not recommended specially if you have a lot of water in your map.
Thank you Ali, can you please elaborate more on how to do it, if the box collider for example should be 2d itself or not, and such.
yes box collider 2D . click any game object in the scene & add component BoxCollider2D & in this component you will see a cheek box named Is Trigger cheek it .
Your answer
Follow this Question
Related Questions
How to check if player is rapidly rotating the joystick? 2 Answers
How do I make a dash attack while doing a top down 2d game 0 Answers
When I build and run my project it seems that its lacking, plz help?! 0 Answers
Load Scene Unity by Application.LoadLevelAsync 0 Answers
how to make the sprite invinsible and reappear and how to call the sprite data from another script 0 Answers