Jump to content
  • Advertisement
Sign in to follow this  
imontheverge7

Tilemap collision problem

This topic is 1370 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!