Sign in to follow this  

Tilemap collision problem

This topic is 1185 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

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

This topic is 1185 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this