Reflecting laser beams off surfaces

0 favourites
From the Asset Store
296 high-quality footsteps sounds specially crafted to help you put sound to your games
  • Hi, I've just started using Construct 2 and I'm looking to add lasers that reflect off selected surfaces. I've been working on it for a while now, and can't seem to figure out how to go about getting this effect.

    I'm looking for something very similar to the effect in the demogame "Can't turn it off", only the position of the laser "cannons" will be fixed rather than controlled by mouse movement.

    I've tried searching the forums/tutorials with no luck. If someone could help me with this, or point me to an old topic/tutorial if one exists, that would be much appreciated.

    Thanks in advance, Nimtrix.

    <font size="1">Edit: Typo</font>

  • Thats a cool game. I would love to see the CAPX

  • Send a PM to Animmaniac if you want his answer. I must admit I also wonder how he did it. I did the same effect on construct classic using a kind of chain reaction with instant hit bullets to get some coordinates and drawing lines between them. But I don't think it's doable like that in c2.

  • Do you think Animmaniac can share it with the forum? There's a lot of really interesting things in that game! I'm still trying to figure out how to make speech bubbles work correctly and would love to see what makes his game tick.

  • I think Animmaniac may have did something like this:

    http://dl.dropbox.com/u/5426011/examples%208/lazer.capx

  • Awesome! Thanks R0J0hound

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Awesome indeed, thanks for your help R0J0hound. This should work perfectly for my project.

  • Nice one indeed

  • I was looking for something like this.

    Thanks.

  • Fantastic stuff ROJO. I've seen a couple of capx for lasers and that has to the best so far!

  • Can someone reupload R0J0's example? I'd like to take a look.

  • Wolod

    The link provided stillworks for me..

  • spongehammer

    It works now. I can swear I've got 404 error few minutes ago. Maybe some issues with the Dropbox.

  • Hey R0J0hound

    I was wondering if there are now better alternatives to your examples, I am trying to achieve something like this:

    The issue I am facing is finding the right balance between accuracy and speed. I was thinking on maybe using line of sight to pick up the nearest reflecting surface, draw the laser, then move to the next segment. But I have no idea if it's currently the best approach.

    Also why are you multiplying sin and cos by 16 in the example?

  • 0plus1

    There are probably other ways to do it. One would be to use raycasting by calculating the intersection of two lines. The example here just does it by steps. The 16 is the distance the laser moves per step. It works only with horizontal or vertical walls though.

    The problem is basically:

    Thinking of the end of a laser as a moving object,

    move it till it hits a wall,

    using the angle of the wall calculate the new angle of the object and repeat.

    If you use raycasting math it can be 100% precise. I did the math for it a while ago and made a quick example here:

    https://www.dropbox.com/s/1tzd6emtsbdpx ... .capx?dl=1

    /examples32/raycast_math.capx

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