How do I create a laser beam that is partially or wholly blocked/destroyed?

0 favourites
  • 7 posts
From the Asset Store
Fully commented source code/event sheet & sprites to create a space shooter game
  • Hey there, I'm conceptualizing a hide-and-seek sort of game where It obliterates other players with a massive laser beam.

    The issue I am having is that I have literally no idea how to build the laser the way that I want. I want the beam to be blocked by anything that isn't a player's body, essentially. Or even maybe blocked by a player: hide behind a corpse to shelter yourself from the laser.

    Point is, I want the beam to be blocked by solids, but have portions of the beam continue. Here's a simple concept drawing.

    I was considering... would it be possible to use, like... a tilemap? Like a tilemap of many 1x1 squares? It doesn't seem very practical but... I dunno, that's all I could think of. Or maybe using a shadow caster somehow...

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • redblobgames.com/articles/visibility

    This can be done with a canvas object and the line of sight behavior. More often used to create vision cones and line of sight masks, but the same principles apply. Note that this is decidedly not a beginner topic.

  • I'm not totally new to C3, but I'm learning new things every day. Let me see if I can sort of piece together the idea.

    So the concept that I believe I am reading isis that the drawing canvas is what will visually and physically represent the beam, and we are using line of sight to use raycasting in order to figure out what the shape of that beam that we are drawing into the drawing canvas will be, right?

  • That's the gist of it. A directional ray with a width will be significantly different than an omnidirectional cast from a single point though.

    Here are some experiments I put together when the LOS cast ray feature first game out, it's not really exactly suitable for your application, but you might be able to find something you can use in there. dropbox.com/s/m6x32uzqcjlf8sk/VisualLOS.c3p

    The dynamic visual representation of a beam getting blocked is the hard part, actually checking if you got hit or not can be done easily with the line of sight behavior.

  • That was something that I was concerned about to start with: all these examples create cone-shaped lights rather than straight beams. I suppose I could sort of add invisible "blinders" to block the ray into a straight line....

    I feel like I want the beam firer to remain still while shooting for the sake of fairness. However, If I can figure out how to update the beam, then I'll give it a shot.

  • If I were to approach this efficiently, I would first identify each corner in the potential area of affect, and cast a ray just above and below in line with that, similar to what I did in the radial example.

  • Put ten beams all pointing the same way and originating from points each 4 or 5 pixels over from each other. Then treat each mean separately. The low ones will get blocked, the higher ones will get through. If you make them fuzzy it will seem like one big partly blocked beam.

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