I am trying to accomplish the "Basic Arcade Collision Response" from the PolyColly tutorial, but without the physics. All I want is for it to be basic but correct). This is what I have modified the code to but I'm not getting the functionality that I would expect, the player is sticking to the polygons and sometimes penetrating the surface.
Again.. trying to keep it simple just using the arrow keys to modify the offset of the player (redPoly).
protected override void Update(GameTime gameTime)
{
// Allows the game to exit
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();
//player position update
float amount = 40;
Vector2 offset = Vector2.Zero;
KeyboardState state = Keyboard.GetState();
if (state.IsKeyDown(Keys.Up))
offset += new Vector2(0, -amount);
if (state.IsKeyDown(Keys.Down))
offset += new Vector2(0, amount);
if (state.IsKeyDown(Keys.Left))
offset += new Vector2(-amount, 0);
if (state.IsKeyDown(Keys.Right))
offset += new Vector2(amount, 0);
//get the list of collisions
List<CollisionResult> collisions = new List<CollisionResult>();
foreach (Polygon p in polygons)
{
float t = 1.0f;
Vector2 N = Vector2.Zero;
Vector2 relPos = redPoly.Position - p.Position;
Vector2 relDisplacement = offset;
if (Collide(redPoly, p, relPos, relDisplacement, ref N, ref t))
{
if (t < 0)
{
ProcessOverlap(ref redPoly, N, t);
}
else
{
ProcessCollision(ref redPoly, N, t, ref offset);
}
}
}
redPoly.Position += offset;
base.Update(gameTime);
}
Does this look correct to you guys?
Thanks,
Mark.