Skip to main content
replaced http://gamedev.stackexchange.com/ with https://gamedev.stackexchange.com/
Source Link

The code looks alright, i'm going to assume it works, i don't code in XNA, so i don't know which objects are yours. The issue is that you're not checking which collision resolution is the smallest. If either x or y velocity is 0 then

    if(Math.Round(velocity.X) != 0.0f) {
        HandleCollisions2(Direction.Horizontal);
    }
    if(Math.Round(velocity.Y) != 0.0f) {
        HandleCollisions2(Direction.Vertical);
    }

is going to sort it for you (since there's possible collision only along the vertical or horizontal axis). However, if both of those velocities are different than zero then the collision is going to get solved for the horizontal axis first, then there won't be any collision so the vertical collision function won't do anything.

If you want to fix this, check both vertical and horizontal collision and find the smallest displacement vector, then resolve collision.

If you want to do what David explained in this answerthis answer (which the answer you linked is based on) then you'll have to separate your x and y movement and collision checking. Right now, you're calling position += velocity * (float)gameTime.ElapsedGameTime.TotalSeconds; which is not what David was advocating.

The code looks alright, i'm going to assume it works, i don't code in XNA, so i don't know which objects are yours. The issue is that you're not checking which collision resolution is the smallest. If either x or y velocity is 0 then

    if(Math.Round(velocity.X) != 0.0f) {
        HandleCollisions2(Direction.Horizontal);
    }
    if(Math.Round(velocity.Y) != 0.0f) {
        HandleCollisions2(Direction.Vertical);
    }

is going to sort it for you (since there's possible collision only along the vertical or horizontal axis). However, if both of those velocities are different than zero then the collision is going to get solved for the horizontal axis first, then there won't be any collision so the vertical collision function won't do anything.

If you want to fix this, check both vertical and horizontal collision and find the smallest displacement vector, then resolve collision.

If you want to do what David explained in this answer (which the answer you linked is based on) then you'll have to separate your x and y movement and collision checking. Right now, you're calling position += velocity * (float)gameTime.ElapsedGameTime.TotalSeconds; which is not what David was advocating.

The code looks alright, i'm going to assume it works, i don't code in XNA, so i don't know which objects are yours. The issue is that you're not checking which collision resolution is the smallest. If either x or y velocity is 0 then

    if(Math.Round(velocity.X) != 0.0f) {
        HandleCollisions2(Direction.Horizontal);
    }
    if(Math.Round(velocity.Y) != 0.0f) {
        HandleCollisions2(Direction.Vertical);
    }

is going to sort it for you (since there's possible collision only along the vertical or horizontal axis). However, if both of those velocities are different than zero then the collision is going to get solved for the horizontal axis first, then there won't be any collision so the vertical collision function won't do anything.

If you want to fix this, check both vertical and horizontal collision and find the smallest displacement vector, then resolve collision.

If you want to do what David explained in this answer (which the answer you linked is based on) then you'll have to separate your x and y movement and collision checking. Right now, you're calling position += velocity * (float)gameTime.ElapsedGameTime.TotalSeconds; which is not what David was advocating.

added 1 characters in body
Source Link
dreta
  • 3.5k
  • 4
  • 22
  • 37

The code looks alright, i'm going to assume it works, i don't code in XNA, so i don't know which objects are yours. The issue is that you're not checking which collision resolution is the smallest. If either x or y velocity is 0 then

    if(Math.Round(velocity.X) != 0.0f) {
        HandleCollisions2(Direction.Horizontal);
    }
    if(Math.Round(velocity.Y) != 0.0f) {
        HandleCollisions2(Direction.Vertical);
    }

is going to sort it for you (since there's possible collision only along the vertical or horizontal axis). However, if both of those velocities are different than zero then the collision is going to get solved for the horizontal axis first, then there won't be any collision so the vertical collision handler never gets calledfunction won't do anything.

If you want to fix this, check both vertical and horizontal collision and find the smallest displacement vector, then resolve collision.

If you want to do what David explained in this answer (which the answer you linked is based on) then you'll have to separate your x and y movement and collision checking. Right now, you're calling position += velocity * (float)gameTime.ElapsedGameTime.TotalSeconds; which is not what David was advocating.

The code looks alright, i'm going to assume it works, i don't code in XNA, so i don't know which objects are yours. The issue is that you're not checking which collision resolution is the smallest. If either x or y velocity is 0 then

    if(Math.Round(velocity.X) != 0.0f) {
        HandleCollisions2(Direction.Horizontal);
    }
    if(Math.Round(velocity.Y) != 0.0f) {
        HandleCollisions2(Direction.Vertical);
    }

is going to sort it for you (since there's possible collision only along the vertical or horizontal axis). However, if both of those velocities are different than zero then the collision is going to get solved for the horizontal axis first, then there won't be any collision so the vertical collision handler never gets called.

If you want to fix this, check both vertical and horizontal collision and find the smallest displacement vector, then resolve collision.

If you want to do what David explained in this answer (which the answer you linked is based on) then you'll have to separate your x and y movement and collision checking. Right now, you're calling position += velocity * (float)gameTime.ElapsedGameTime.TotalSeconds; which is not what David was advocating.

The code looks alright, i'm going to assume it works, i don't code in XNA, so i don't know which objects are yours. The issue is that you're not checking which collision resolution is the smallest. If either x or y velocity is 0 then

    if(Math.Round(velocity.X) != 0.0f) {
        HandleCollisions2(Direction.Horizontal);
    }
    if(Math.Round(velocity.Y) != 0.0f) {
        HandleCollisions2(Direction.Vertical);
    }

is going to sort it for you (since there's possible collision only along the vertical or horizontal axis). However, if both of those velocities are different than zero then the collision is going to get solved for the horizontal axis first, then there won't be any collision so the vertical collision function won't do anything.

If you want to fix this, check both vertical and horizontal collision and find the smallest displacement vector, then resolve collision.

If you want to do what David explained in this answer (which the answer you linked is based on) then you'll have to separate your x and y movement and collision checking. Right now, you're calling position += velocity * (float)gameTime.ElapsedGameTime.TotalSeconds; which is not what David was advocating.

added 130 characters in body
Source Link
dreta
  • 3.5k
  • 4
  • 22
  • 37

The code looks alright, i'm going to assume it works, i don't code in XNA, so i don't know which objects are yours. The issue is that you're not checking which collision resolution is the smallest. If either x or y velocity is 0 then

    if(Math.Round(velocity.X) != 0.0f) {
        HandleCollisions2(Direction.Horizontal);
    }
    if(Math.Round(velocity.Y) != 0.0f) {
        HandleCollisions2(Direction.Vertical);
    }

is going to sort it for you (since there's possible collision only along the vertical or horizontal axis). However, if both of those velocities are different than zero then the collision is going to get solved for the horizontal axis first, then there won't be any collision so the vertical collision handler never gets called.

If you want to fix this, check both vertical and horizontal collision and find the smallest displacement vector, then resolve collision. 

If you want to do what David explained in this answer (which the answer you linked is based on) then you'll needhave to do some more checkingseparate your x and y movement and collision checking. Right now, but the general issue i explained still standsyou're calling position += velocity * (float)gameTime.ElapsedGameTime.TotalSeconds; which is not what David was advocating.

The code looks alright, i'm going to assume it works, i don't code in XNA, so i don't know which objects are yours. The issue is that you're not checking which collision resolution is the smallest. If either x or y velocity is 0 then

    if(Math.Round(velocity.X) != 0.0f) {
        HandleCollisions2(Direction.Horizontal);
    }
    if(Math.Round(velocity.Y) != 0.0f) {
        HandleCollisions2(Direction.Vertical);
    }

is going to sort it for you (since there's possible collision only along the vertical or horizontal axis). However, if both of those velocities are different than zero then the collision is going to get solved for the horizontal axis first, then there won't be any collision so the vertical collision handler never gets called.

If you want to fix this, check both vertical and horizontal collision and find the smallest displacement vector, then resolve collision. If you want to do what David explained then you'll need to do some more checking, but the general issue i explained still stands.

The code looks alright, i'm going to assume it works, i don't code in XNA, so i don't know which objects are yours. The issue is that you're not checking which collision resolution is the smallest. If either x or y velocity is 0 then

    if(Math.Round(velocity.X) != 0.0f) {
        HandleCollisions2(Direction.Horizontal);
    }
    if(Math.Round(velocity.Y) != 0.0f) {
        HandleCollisions2(Direction.Vertical);
    }

is going to sort it for you (since there's possible collision only along the vertical or horizontal axis). However, if both of those velocities are different than zero then the collision is going to get solved for the horizontal axis first, then there won't be any collision so the vertical collision handler never gets called.

If you want to fix this, check both vertical and horizontal collision and find the smallest displacement vector, then resolve collision. 

If you want to do what David explained in this answer (which the answer you linked is based on) then you'll have to separate your x and y movement and collision checking. Right now, you're calling position += velocity * (float)gameTime.ElapsedGameTime.TotalSeconds; which is not what David was advocating.

added 130 characters in body
Source Link
dreta
  • 3.5k
  • 4
  • 22
  • 37
Loading
Source Link
dreta
  • 3.5k
  • 4
  • 22
  • 37
Loading