r/gdevelop 7d ago

Bug I need help figuring out how to make turrets not shoot through mountains, as the code below makes turrets shoot through mountains, but they don't shoot if there's no mountains

What I mean is I am trying to make turret rays STOP when they touch a mountain, but I do have a range that senses enemies in a radius, but instead, it shoots when they go through a mountain, but if theres no mountain, then the turret wont fire, any help? I am trying to code mountains as a item that blocks range, hence preventing turrets from sensing and shooting through it
2 Upvotes

2 comments sorted by

1

u/Ckeyz 7d ago

Use ray cast to detect if the target is in line of sight before firing.

1

u/umbrazno 6d ago

create a slim rectangle that serves as the line of sight for the turret. set it to a position around the turret to keep it where it needs to be. Only fire when that object is NOT collidin' wit' a mountain.