Best way to implement 'push out'?

Get help using Construct 2

Post » Wed Jul 10, 2013 3:27 pm

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?Dalal2013-07-10 16:59:06
Image
B
10
S
3
G
2
Posts: 196
Reputation: 2,053

Post » Wed Jul 10, 2013 3:57 pm

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.
B
28
S
8
G
5
Posts: 429
Reputation: 6,977

Post » Wed Jul 10, 2013 4:06 pm

Thanks for sharing that approach. Because of all varieties of slopes, that approach probably won't work in my case.
Image
B
10
S
3
G
2
Posts: 196
Reputation: 2,053

Post » Wed Jul 10, 2013 7:07 pm

The custom movement behavior has a push out action.
Moderator
B
91
S
32
G
33
Posts: 3,005
Reputation: 27,552

Post » Wed Jul 10, 2013 7:26 pm

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: [code]floor(Character.Y) + (Obstacle.Y - floor(Obstacle.Y)[/code] 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.Dalal2013-07-10 19:34:15
Image
B
10
S
3
G
2
Posts: 196
Reputation: 2,053


Return to How do I....?

Who is online

Users browsing this forum: Aquanex2, jhjconstruct, Tuiii and 7 guests