- Home /
How to make an enemy stop and start movement in a tower defence game?
I'm making a tower defence game and I want to make it so that when the enemies hit an obstacle or and enemy infront, that they stop. When the obstacle or enemy infront is destroyed I want them to move forward again.
I'm using node based transportation for these enemies, from the Brackeys tutorial. It's been super helpful so far, and I'm at a poitn where I want to add extra things into the game.
Just to clarify, the enemies do stop when they encounter an obstacle or other enemy, they just won't move again after. The enemies also have a rigidbody so they can detect triggers, and obstacles and enemies both have a trigger collider on them.
Code: private void OnTriggerEnter(Collider col) { if (col.CompareTag("Obstacle") || col.CompareTag("Enemy")) { canMove = false; Debug.Log("Stop"); } } private void OnTriggerStay(Collider col) { if (col.CompareTag("Obstacle") || col.CompareTag("Enemy")) { if (col.GetComponent<Enemy>().health <= 0) { Movement(); Debug.Log("Start Moving!"); } } }
Your answer
Follow this Question
Related Questions
Damaging Enemies 1 Answer
OnTriggerEnter2D not working with boolean 1 Answer
Roll-A-Ball enemyball[Personal Extra] Cant get it to follow the player 2 Answers
OnTriggerStay weird behaviour 0 Answers
How do I get GameObjects to look at me? 2 Answers