Checking for collisions where an object could end up?

0 favourites
  • 5 posts
From the Asset Store
This is a single chapter from the "Construct Starter Kit Collection". It is the Student Workbook for its Workshop.
  • This is conceptually a little complicated so here's a screenshot of the project:

    So this project uses the Platform behavior in conjunction with the Solid collision filter/tags. You can see in the screenshot above that there are 7 "lanes" of collision/depth, and the player object only collides with solids tagged with the lane theyre in.

    This works fine, but we run into edge-case issues when switching lanes. Currently the game does the following to move lanes up down:

    1. First, it calls a function that checks if the position above/below the player in the lane theyre trying to move to is free.
    2. Next, it initiates a tween that moves the player either up or down lanes, and temporarily disables the lane collision checking while the tween is active.
    3. Finally, when the tween is finished the game updates the collision filter for the player object to check for collisions in the lane the player has moved to.

    If the player is standing still, this works fine. We run into problems when the player is moving left/right during a lane change, because during the tween the player continues to move left/right, and the position they end up at when the tween ends and re-initiates collisions could include a solid the player is now stuck in.

    Up until now I've been able to slightly combat this issue by checking directly above/below the player and slightly in front of them as well, but this has only lessened the frequency of this issue, it still occurs.

    I could of course stop the players horizontal movement during the lane change tween, but this makes movement really clunky and unsatisfying, so that's not ideal.

    Any suggestions on how to accomplish this would be appreciated, if I could predict the range of locations the player could end up at during step 1, then I feel like I could eliminate this issue, but I don't know how to do that or if there is a better alternative. Thank you!

  • I'd use an invisible helper sprite, horizontally positioned relative to the current velocity of your player object times the time it takes to change lanes. Use this object to test for collisions at the destination.

    You would replace your player object with this helper object in function 1.

  • That makes sense, its not quite as self contained as I'd hoped but it does seem straighforward, I'll try it out and see how it goes!

  • A container might be useful as well to associate the player sprite with the helper sprite and assist with picking.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • As a quick update, oosyrag's suggestion worked pretty well, though I didn't use the container idea. Mainly because this only needs to be checked during lane changes, so I create a "LaneChecker" object in the function that checks to see if the lane the player is trying to move into is obstruction free. This object is created, positioned, and sized based on the players position and VectorX values, and then I just check to see if it is overlapping anything in the new lane.

    Regardless of if it is or isn't, the object is destroyed immediately at the end of the checker function.

    Thanks for the suggestion oosyrag! It's much more consistent than the old patch-job I had, and it was easy to test by simply not destroying the lanechecker object at the end of the function and changing its sprite based on whether it would allow a lane change or not.

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