"When the enemy sees you" event

Hello my dear friends.
I have a player (green) and an enemy (red) and I want to create an event, when the enemy see you.
I created a cone and when the player is in contact with a cone, event is activated. But event is activated, even when the player is behind the wall. How to make it correct? I thought about firing invisible objects from the enemy, which will be removed when hitting the wall. Any ideas or solutions? Thank you very much.

One of the ideas I had was to cast a physics ray from the “Enemy” to the “Player” after detecting its presence in the “Cone”. Then get the objects being Hit. If the hit object is a “Wall”, then the enemy does not see the player. If the ray hits the “Player”, then the “Enemy” sees the “Player”

2 Likes

Thank you for ideas but Cast Physics Ray Node not working for me


What im doing wrong? Ray is between two blocks and when Cube going between blocks, nothing happening.

Edit: Problem solved. Dynamic physics properties must be disabled for the cube.

Now it won’t be a problem to create what I wanted.

Thank you very much.

Edit2:
Hmmm interesting, now it works even the Dynamics is enabled.

1 Like
Hmmm interesting, now it works even the Dynamics is enabled.

Maybe it is this:
The “Collision Filter” term in the “Cast Physics Ray” node must be set so that the objects that you want to detect are in the same collision group. This is found in the physics tab of each object.

1 Like

It is possible because i set Collision Filter to 1. Thanks for more info. I like to learn something new.

1 Like

To avoid crashes, You should use an “is not none” node inbetween the “get name” node, as this can otherwise cause a crash if the ray happens to not hit an object on its path. The “is not none” node will ensure it only looks for a name when the ray hits an actual object :slight_smile:

2 Likes