[Solved] Raycast

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.

2 Likes

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.

8 Likes

When you need help about events, you can see on your screen at bottom center, a button called
â€śHELP FOR THIS CONDITIONâ€ť

1 Like

@Bouh actually â€śHelp for this conditionâ€ť (for the 2 raycast conditions) lead to a moved page:

The link to follow brings here, where no info about raycast can be found: Objects [GDevelop wiki]

I hope this report might help

Iâ€™m upping this post because iâ€™m trying to document an issue, probably a bug, i encounter with raycast

1 Like

There is indeed no documentation for the raycast on the wiki

1 Like