How do I have my lightning gun blocked by walls?

Get help using Construct 2

Post » Sat Oct 25, 2014 11:13 pm

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?
B
5
S
1
Posts: 59
Reputation: 497

Post » Sat Oct 25, 2014 11:51 pm

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.
B
45
S
21
G
65
Posts: 1,118
Reputation: 38,227

Post » Sun Oct 26, 2014 4:41 am

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?
B
5
S
1
Posts: 59
Reputation: 497

Post » Sun Oct 26, 2014 5:19 am

okay, here's a capx I put together showing how to do it.
You do not have the required permissions to view the files attached to this post.
B
45
S
21
G
65
Posts: 1,118
Reputation: 38,227

Post » Sun Oct 26, 2014 7:25 am

Thank you so much Im still trying figuring out where everything is so this helped me a ton
B
5
S
1
Posts: 59
Reputation: 497


Return to How do I....?

Who is online

Users browsing this forum: Ashley, tarek2 and 45 guests