Best way to implement 'push out'?

0 favourites
  • 5 posts
From the Asset Store
Best car suspension with spring effect and very cool terrain generation.
  • I'm writing a custom platform engine for my game, and I had a question about 'pushing out' an object from another object. In simple terms, say Mario is falling and he overlaps a platform. We now need to perform a 'push out' loop where we slowly move Mario up until he no longer overlaps and is 'flush' with the platform.

    C2 uses sub-pixel precision, so pushing out an object pixel by pixel will yield inconsistent results visually i.e sometimes Mario will be a pixel too high. I've found that pushing out an object at less than a pixel per iteration is more stable, but no matter how small I go (even at 0.01 px/iteration), Mario is still vibrating ever so slightly, giving a blurred look.

    Something seems fundamentally wrong with my approach. What's the best way to implement a 'push-out' so that by the end of it 'Mario' is no longer overlapping the obstacle and he is flush with it?

  • One solution is to make it when it is no longer pushing out, set Mario's Y to that of the platform. Might not work for you depending on how you have your game set up, but that method has solved a number of problems for me in the past.

  • Thanks for sharing that approach. Because of all varieties of slopes, that approach probably won't work in my case.

  • The custom movement behavior has a push out action.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I should have clarified. I'm doing a lot of specialized collision detection (my overlap detection is not simply the C2 condition 'Is Character Overlapping Obstacle'). The push out that comes with Custom Movement cannot test for collisions at an offset for example. I have slopes which the character walks along using his bottom middle point and Custom Movement's push out would try to push him out when it's not supposed to.

    Anyway, I think I solved the problem using the following technique:

    On the character's initial overlap with obstacle, offset the character to match the sub-pixel offset of the obstacle i.e Set the position to the following:

    floor(Character.Y) + (Obstacle.Y - floor(Obstacle.Y)

    Now resume the loop as normal, and by the end, the character should be a perfect whole pixel above the obstacle.

    It works quite well so far, except for a subtle jitter when walking up slopes, likely from the offset matching that I'm doing. Hmm... any other ideas are welcome.

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