Tilemap collision problem

Started by
1 comment, last by imontheverge7 9 years, 7 months ago

I have a method here that I call within my update method to return true when my player collides with a certain tile.


            if (!CheckCollision())
            {
                player.Update();
            }

        private bool CheckCollision()
        {
            foreach (CollisionTile tile in map.CollisionTiles)
            {
                if (tile.TileType == "stone" && player.rectangle.Intersects(tile.Rectangle))
                {
                    return true;
                }

                if(tile.TileType == "water" && player.rectangle.Intersects(tile.Rectangle))
                {
                    return true;
                }
            }
            return false;
        }

When I collide with a tile my player will stop, but if I move in a different direction my player won't move. I'm stuck on how to figure out a way to make my player move again.

Advertisement

It will probably not move because it's stuck inside the collision.

One solution could be:

1. Store current player position.

2. Update the player position.

3. Check the new position for collisions.

4. If a collision was detected, move back to the original position (stored in step 1).

Hello to all my stalkers.

Awesome that worked. Thanks!

This topic is closed to new replies.

Advertisement