Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - FerrisWheel

Pages: [1]
1
General / Trouble with the collision code from the wiki
« on: July 28, 2010, 11:32:55 pm »
I'm using the code somebody has kindly written for us on the wiki (link), and am having trouble with the collisions. I'm trying to get the collision between two squares, yet using both BoundingBox and PixelPerfect collision tests, the rectangle always seems move a few pixels into the box.

Code: [Select]
if(Collision::PixelPerfectTest(sprite, collidables[i]))
{
      sprite.SetPosition(sprite.GetPosition().x + 100 * time_step, sprite.GetPosition().y); //move back to original position
      while(Collision::PixelPerfectTest(sprite, collidables[collided_with]))
      {
           sprite.SetPosition(sprite.GetPosition().x - 1, sprite.GetPosition().y);
      }
}


Before this code I move the player by -100, then test collision, if there is a collision I move it +100 to it's original position and loop through moving one pixel at a time, testing collision at each. Yet as it stops they just intersect slightly. Why does this happen?

Pages: [1]