0
votes

I'm making a basic platformer engine in AS3, and I'm currently implementing gravity. The gravity currently lets the player sink a few pixels into the ground when it lands (depending on the player's speed), and I don't want that.

I want to be able to test collisions 1 frame ahead of time (sweep testing), and if a collision will happen in the next frame, I want the player to stop 0px into the ground, regardless of the player's speed.

I also want pixel-perfect collisions that take the shape of the terrain, so I've been using Corey O'Neil's Collision Detection Kit (CDK), which works very well for detecting collisions, but I can't work out how to make it predict them. I'm not sure if this is the best library to use.

I'm not sure about Box2D; I feel it's too much for what I want.

Any idea of how can I do pixel-perfect sweep tests in AS3?

2

2 Answers

0
votes

Box2D should be pretty good for small projects as well, also in case if you wish to scale up later...

If you need quicker dive in, have a look at Quick Box 2d.

There are couple of good tutorials (here & here) as well.

0
votes

I want to be able to test collisions 1 frame ahead of time (sweep testing), and if a collision will happen in the next frame, I want the player to stop 0px into the ground, regardless of the player's speed.

In you game loop, where you are checking the colisions, just add the movement that will be done in the next frame, the current Y speed. Something like this:

if(currentYSpeed + player.y >= ground.y)
{
    player.y = ground.y
}else
{
    player.y += currentYSpeed;
}