How do I have my lightning gun blocked by walls?

  • I have a lightning gun like in Quake and when firing, the laser extends from the gun to the mouse. But I need it to stop when it hits a wall, even if the mouse is behind the wall. How do I stop the laser at the wall?

  • You have to check the space between the gun and the mouse to see if the wall is in the path of it.

    One way is to use a For loop and calculate the floor(distance(gunx,guny,mousex,mousey)) as the max value for the For loop.

    Then in the loop, use the loopindex("nameofloop") expression while you check if a position is overlapping a wall. Get the angle, and then the distance to check from gun will be the loopindex("name")..

    If it overlaps, then you have the position to stop the laser and you can stop the loop.

    You can also divide the distance by 5 for example if you don't want to check every position, but then you have to multiply the position by 5 when you check if overlapping.

  • Thanks for the reply, but I'm not sure what you mean by the "loopindex("nameofloop")" expression, i cant find that anywhere. Can you maybe screencap where that is or what this event sheet would look like?

  • okay, here's a capx I put together showing how to do it.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Thank you so much Im still trying figuring out where everything is so this helped me a ton

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)