Skip to main content
Bounty Awarded with 50 reputation awarded by Rafael Almeida
Rewrote answer to fit
Source Link
ChrisUC
  • 412
  • 2
  • 10

It seems like your problem is here:

                    if (collision == GameMap.TileCollision.Block || IsOnGround)
                    {
                        // Resolve the collision along the Y axis.
                        Position = new Vector2(Position.X, Position.Y + depth.Y);

                        // Perform further collisions with the new bounds.
                        bounds = BoundingRectangle;
                    }

You should take away depth.Y from Position.YIf I understand correctly, as co-ordinates in game systems typically originate from (0your movement issue can be resolved by David's answer,0) but you want to implement being the top left of the mapable to move upwards through platforms.

In addition, This can be solved with an additional if statement. When you shouldcollide with a platform, check the players Y velocity and the target block type to see which edgeif you should pushcan move upwards through it. If the player to depnding on whichplayer's Y velocity is less deepset above 0, instead of just pushing higher Y values up and higher X values toor the rightblock type cannot be moved through upwards, then resolve the collision as normal.

It seems like your problem is here:

                    if (collision == GameMap.TileCollision.Block || IsOnGround)
                    {
                        // Resolve the collision along the Y axis.
                        Position = new Vector2(Position.X, Position.Y + depth.Y);

                        // Perform further collisions with the new bounds.
                        bounds = BoundingRectangle;
                    }

You should take away depth.Y from Position.Y, as co-ordinates in game systems typically originate from (0,0) being the top left of the map.

In addition, you should check to see which edge you should push the player to depnding on which is less deep, instead of just pushing higher Y values up and higher X values to the right.

If I understand correctly, your movement issue can be resolved by David's answer, but you want to implement being able to move upwards through platforms. This can be solved with an additional if statement. When you collide with a platform, check the players Y velocity and the target block type to see if you can move upwards through it. If the player's Y velocity is set above 0, or the block type cannot be moved through upwards, then resolve the collision as normal.

added 190 characters in body
Source Link
ChrisUC
  • 412
  • 2
  • 10

It seems like your problem is here:

                    if (collision == GameMap.TileCollision.Block || IsOnGround)
                    {
                        // Resolve the collision along the Y axis.
                        Position = new Vector2(Position.X, Position.Y + depth.Y);

                        // Perform further collisions with the new bounds.
                        bounds = BoundingRectangle;
                    }

You should take away depth.Y from Position.Y, as co-ordinates in game systems typically originate from (0,0) being the top left of the map.

In addition, you should check to see which edge you should push the player to depnding on which is less deep, instead of just pushing higher Y values up and higher X values to the right.

It seems like your problem is here:

                    if (collision == GameMap.TileCollision.Block || IsOnGround)
                    {
                        // Resolve the collision along the Y axis.
                        Position = new Vector2(Position.X, Position.Y + depth.Y);

                        // Perform further collisions with the new bounds.
                        bounds = BoundingRectangle;
                    }

You should take away depth.Y from Position.Y, as co-ordinates in game systems typically originate from (0,0) being the top left of the map.

It seems like your problem is here:

                    if (collision == GameMap.TileCollision.Block || IsOnGround)
                    {
                        // Resolve the collision along the Y axis.
                        Position = new Vector2(Position.X, Position.Y + depth.Y);

                        // Perform further collisions with the new bounds.
                        bounds = BoundingRectangle;
                    }

You should take away depth.Y from Position.Y, as co-ordinates in game systems typically originate from (0,0) being the top left of the map.

In addition, you should check to see which edge you should push the player to depnding on which is less deep, instead of just pushing higher Y values up and higher X values to the right.

Source Link
ChrisUC
  • 412
  • 2
  • 10

It seems like your problem is here:

                    if (collision == GameMap.TileCollision.Block || IsOnGround)
                    {
                        // Resolve the collision along the Y axis.
                        Position = new Vector2(Position.X, Position.Y + depth.Y);

                        // Perform further collisions with the new bounds.
                        bounds = BoundingRectangle;
                    }

You should take away depth.Y from Position.Y, as co-ordinates in game systems typically originate from (0,0) being the top left of the map.