How do I let a laser collide with Tilemap?

1 favourites
  • 15 posts
From the Asset Store
Who wants to be a Millionaire Clone. An educational coding source
  • Hello everyone!

    I would like to create a laserbeam. I have managed to let the laserbeam collide with a tilemap with solid behaviour, but on the edges, the laser still goes through the wall. How can I make the laser more precise so that it really collides with each solid tile?

    Here is a screenshot, how I am doing the laser so far:

  • I still could not fix this issue.

    Any idea how to solve this?

    Here is a gif to show off the strange offset the laser has:

  • Are your tilemap collision boxes set up properly? You can modify the collision polygon for each individual tile in the image editor by double clocking the tile.

  • Yes they are but it didn't cahnge anything. It seems that something is wrong with the Line of Sight behavior but I don't know what exactly. The particle is even misplaced although it should be at the X an Y position of the intersection.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Perhaps check the origin point of your laser. Without seeing your project and how it's set up it's just guesses.

  • Right sure, with the file its easier, here you go :)

    drive.google.com/file/d/1i2OvnAChH2N3pKZEL_DJXIxRj_BQI8ag/view

  • It would also be easier if you isolated the issue and had a layout that showed it or something, but oh well. I made a test layout and it works perfectly fine for me? I have no idea how to find where you were having issues with it.

    dropbox.com/s/ftxm621upms88ij/laserproblem.c3p

  • Right, sorry, next time I will create a own project/layout for it :)

    Yes I have no idea why it is not working. What else could cause this problem in my actual project? I also took now your advice and created a new project with the laser and it works there...

    Maybe a create a new layout and work every step through again with each layer.

  • If I switch off my system for room cameras it works somehow correct. Could this be the problem?

  • The next update:

    The bigger the map and the more right the laser is placed, the offset of the HitX is getting bigger and bigger. Is this some sort of engine bug?

  • That sounds like a parallax issue. Is your laser on the right layer?

  • I also thought that, but double checked it and the lasers are on the same layer as the tilemap abd this layer is not parallax…

  • Ok I was able to recreate it when using high x values on a larger layout. I don't immediately see anything that could be the problem, it could be a bug. Will check in more detail when I get a chance.

  • Found it. Your cast ray action currently is:

    -> LaserTurret: Cast ray from (Self.ImagePointX("Tip"), Self.ImagePointY("Tip")) to (cos(Self.Angle) × Self.LineOfSight.Range, sin(Self.Angle) × Self.LineOfSight.Range) (use collision cells True)

    It should be:

    -> LaserTurret: Cast ray from (Self.ImagePointX("Tip"), Self.ImagePointY("Tip")) to (Self.ImagePointX("Tip") + (cos(Self.Angle) × Self.LineOfSight.Range), Self.ImagePointY("Tip") + (sin(Self.Angle) × Self.LineOfSight.Range)) (use collision cells True)

    Your ray was basically shooting towards somewhere near the origin, but you had set linieofsight range so high that it wasn't easily noticable when aiming always downward.

  • Thank you very much! Finally my headache with this issue is gone. :D

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