[Solved] Raycast


#1

I dont understand rays. Please explain this.

Just be clear and understandable. Please respond fast bc i need to finish my project before (Thursday) 7 PM.


Hi, im new here :)
#2

Object to test against the ray : select an object that you want to hit by the ray.

In the example it is a group called Solid that include the player object and the walls because you don’t want the ray to pass the wall and you want to look specifically for the player in the example if visible or not. If hit by the ray, it is visible.

Source X : the X position where you want to cast the ray from
Source Y: the Y position where you want to cast the ray from.

In the example it is the tanks.

Ray Angle : basically the direction where do you want to cast the ray to

In the example we want to cast the ray from the tanks to the player. At the time there was no action to cast ray to position so this math expression was used to calculate the angle from 2 point. But you can use Raycast to position now instead.

Ray maximum distance : you don’t want a ray to go forever, how far do you want it to go from the start position… In the example it is 600 pixels.

Variable to store position of the intersection : when the ray hit something, it is going to store the X and Y position of the hit that you can use later if you want to know where the hit happened exactly.

Then, you need to use a sub event and in the sub event you need to use the condition to check how many solid was picked by the ray, in this case the player (the player is member of the solid group). If the number picked is > 0 then the tank see the player because the player was picked.

I believe this is the only event in GDevelop that require a sub-event specifically so it is not as flexible as the other events in GD and a bit unusual. You must look for the objects picked by the ray in a sub-event as demonstrated in the example and you need to setup the raycast as I have explained above.


#3

When you need help about events, you can see on your screen at bottom center, a button called
“HELP FOR THIS CONDITION”
:wink: