Enemy auto shoot if can


I have a situation where there are 3 object: player, enemy and wall. Enemy automatically shoot on player but when player is behind the wall I need to enemy stop shooting. Any suggestions to code this? Thanks

Just an idea: your enemy could shoot fast invisible small physical circle objects towards player, with type bullet and sensor=true. When the bullet collides with a wall, you know you are hidden, so he should stop shooting real bullets (but continue shooting invisible bullet). This way you would have almost no coding to do to achieve the expected result.

If the physics engine is involved in this puzzle, you can more easily use raycast or raycastAll and check if the wall is in the list of objects in between.

Thank you @Codeslinger this is exactly what I was looking for. Also thanks @Jmv38, interesting idea :slight_smile: