Raycast Collision

Hello all, is it possible that the raycast includes collisions? in my case the player is revealed through a wall

red is a turret - blue the player
exampleray

Yes. You need to provide the raycast command a list of objects to check for collision. Use a group for this. By excluding the wall from the group list, it should spot the player through the wall.

I suggest you this example. This may help you. :wink:
https://editor.gdevelop-app.com/?project=example://basic-artificial-intelligence

1 Like

Thank you, yeah I have already tried the example. The event whether the collision has occurred with a specific object is also not in this example.

It simply checks β€œThe number of Perso objects > 0”

If the raycast hit the player, set the Alerte value of the tank to 1
Note this solution works only because we have only a single player in the scene.
Otherwise we should be using the variables IntersectionX and IntersectionY in order to check which instance was hit by the raycast

What does a event with the intersection would look like? I thought IntersectionX == Player.X() and IntersectionY == Player.Y() but due to rounding differences this if-state will never be true

This example shows how to emit a raycast from an object and how the other objects on the same group can works blocking the raycast (you have to put your character and the obstacles in the same group and emit the raycast to the group, not to the character). The action is to change an object variable, and then when the object variable change, more events start working. This is a base to start, the events after this depends on you game and what is your object.