How do I make aiming line with thickness?

  • Hello I would like to make aiming helper line with some thickness.

    For better understanding take advance example "Instant hit laser" (from Scirra) there is similar behavior with that laser that changing length due to obstacles but there is used Line of sight behavior and "Cast ray", but that ray has 0 thickness.

    I would like to make similar thing but that line has some thickness like on this example image.

    I will be really glad for any help and tips how to make it. I was trying something with "firing" many bullets with high speed and due to theirs collisions changing length of line but it is not instant and seems not ideal solution for performance.

  • Please any solution how to make it? :)) Thanks in advance.

  • So you want something similar to ray casting, but you want the ray to have width. If any part of the ray overlaps with an object then you want the entire ray to be occluded. Is this correct?

    You're right that the ray has 0 width. But depending on how you need your beam to work this might not be a problem.

    I've seen a published game created in C3 do a wide laser using ray tracing, and I'm fairly sure they just cast a single ray down the middle. Most players won't notice. The narrower the laser the less noticeable the issue. Suppose that you render the actual beam by stretching a sprite from the source of the ray to the point of it's collision. That sprite has a rectangular collision polygon, so you can use that to check if any enemies touched the beam. Using this technique will not allow enemies to obstruct the beam, but you can check if the laser ( with width ) passed through them!

    A more complex solution is to cast more than 1 ray for your laser. For example cast one ray for the left side and one for the right hand side. If one or both collided with an object then the ray was obstructed, the closest collision is the "real" one. This is faking the collision, so it's not exact. You might have issues with objects that are smaller than the width of the beam, or pointy collision shapes. You can tweak this by adding more ray casts within the laser.

    A final alternative is to use the bullet behaviour. It's reflections don't have the exact angles like raycasting does, but it is quite close to correct and takes into account the shape of the objects collision polygon. You can use bullet stepping to prevent fast bullets from passing through objects erroneously.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Hello I was few days off so I am back and I tried that variant with more rays especially 3 rays. With approx 40px width laser beam it looks okey.

    files.fm/f/rv3tf7kt

    I modified example file adding these rays and set length of beam like min of 3 ray´s length. So thank you for tip I think it will be enough accurate for me :))

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