Hitscan system broken in R174+

0 favourites
  • 10 posts
From the Asset Store
Create complex dialogues with ease with this tool/template!
  • Problem Description

    This hitscan system breaks when using R174 or higher, but works perfectly on R173. No idea what the real cause is, but it might be the collision detection.

    Description of Capx

    Contains simple top-down scene with player, enemies with no AI, and some walls.

    Hitscan algorithm:

    1. Draw a line

    2. Check if any objects are overlapping the line. If true, record the object type, the distance from the object and the origin of the line, and the objects UID.

    a. If it's overlapping a wall, break the wall down into a vector for each side, then find out where on that vector does the line cross. (Line intersection algorithm not by me.)

    b. If overlapping an enemy, stop.

    3. Once all objects are recorded, sort the array on the X axis (This is why 'distance' is on top of the array)

    4. For each element on X axis, do stuff based on what object was hit.

    5. Clean everything up

    Steps to Reproduce Bug

    • Install 174+
    • Run and notice the wacky detection for the lines
    • Install 173
    • Run and notice it works perfectly

    Observed Result

    The line ends at weird positions and outright ignores some walls, especially at strange angles.

    Expected Result

    Line stops at a wall based on the lowest distance

    Affected Browsers

    • Chrome: YES
    • FireFox: YES
    • Internet Explorer: ???

    Operating System and Service Pack

    Windows 7 64-bit Service Pack 2

    Construct 2 Version ID

    Construct 2 R173-R175

  • I forgot to mention that I did not touch the events between different versions. This is purely caused from me going from 173 to 174 or 175.

  • It is always helpful if you can narrow it down to the exact single version that caused it to work differently.

  • I tried it in both r173 and r175 and it appears to work similarly in both cases. Looks like it traces the line through two blocks? Can you explain in more detail exactly what the difference you are seeing is? Also it is difficult to debug a project with 46 events - can you reduce this to a minimal repro that shows the fewest events possible that still demonstrate the change in behavior? Or can you describe which particular event or part of the events are working differently?

  • I tried it in both r173 and r175 and it appears to work similarly in both cases. Looks like it traces the line through two blocks? Can you explain in more detail exactly what the difference you are seeing is? Also it is difficult to debug a project with 46 events - can you reduce this to a minimal repro that shows the fewest events possible that still demonstrate the change in behavior? Or can you describe which particular event or part of the events are working differently?

    I'll try my best to reduce it some more. I was initially worried about breaking it when moving stuff around and deleting objects, so I'll simplify it and re-upload the new capx file.

    I also seemed to have had a stroke and didn't explain what I was trying to achieve with this system, so I'll do that now: Better Instant Bullets/Rays

    I saw the 'Instant Laser' example (Small object stepping forward a few pixels, checking for collision, and stepping again if it didn't hit anything) and tried to apply it to other uses, such as instant bullets and checking if a player can activate a switch or open a door. I wasn't satisfied with the performance and inaccuracy this method used, so I took a look at other games to see how they handle it, specifically the Doom games. (Been playing it since I was very young! ) Using some debugging tools in Doom64Ex, I noticed that bullets and 'uses' were calculated with a line intersecting with objects. After some thinking, I came up with this algorithm.

    I'm probably going to make a tutorial about it at some point, and explain how instant bullets can play a huge part in player feedback, but I updated to the new beta release and was horrified when it suddenly stopped working correctly. It may have been something on my end, but I kept reverting back to 173 and seeing it work like a charm. It's a tad confusing...

    ...Uh...But yeah, story aside, I'll try to narrow the whole thing down some more, and maybe leave comments so there's a better idea what's going on. Cheers Ashley!

  • Alright, I must have been tired last night because I didn't correctly explain how to reproduce the issue. I'm really sorry for making this a huge hassle, but I'm trying my best ._.

    Using WASD or Arrow keys, move the player to the right side of the layout. Then aim to the left and fire. Notice how the hitscan stops at the very last wall instead of the one closest to the player, but when firing from left to right, it works fine (???). R173 didn't have this problem (I removed the wall limit for sake of simplicity):

    R173:

    R175:

    And if you try to hit an enemy (the red squares) with a hitscan, it returns a distance of 0. Not sure why this is happening, but I'm still trying to minimize things some more (ran into some issues when I accidently saved in R175 -_- ) and comment how the system works. I'll get back to you if I find out anything else, or if I realized I forgot something again

  • This is very confusing: when I run it in Chrome in r175, I don't see what you've posted screenshots of. I see this:

    Since this does not appear to match any of your images/descriptions, I don't know what to make of it. Also since we did not change any collision/event related code in r174 as far as I can remember or tell from the changelog I am at a loss as to what we could have modified that would have caused any change in behavior here. On top of that the events implement a relatively complex algorithm with function calls, arrays and loops, so it is very difficult to debug.

    To help me have a chance at figuring out what is going on here it would be invaluable if you can:

    1) reproduce the problem without requiring any user input at all, so I can see exactly the setup you have

    2) simplify the events as far as humanly possible while still demonstrating a change in behavior - ideally <5 events

    3) identify the specific event or feature that is now working differently, and explain precisely what the difference between the versions is

  • Sorry about the delay; I'm going to college this fall and I've been busy making sure everything is ready. I'll try my best to reproduce it and keep it simple. Hopefully then this can all be straightened out, one way or another

  • Phobos002 - we are coming up to a stable release and you haven't updated this bug report. If you don't update it soon then the next stable release might still contain this issue.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Closing, please re-post a simple repro if you still have issues with r178.

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