Why does my player stop when stepping onto a new tile?

Posted by user220631 on Game Development See other posts from Game Development or by user220631
Published on 2014-05-19T18:11:27Z Indexed on 2014/06/06 9:43 UTC
Read the original article Hit count: 244

Me and my friend are creating a game from scratch. He is in charge of art design and I am in charge of coding. I have done well so far with the code, but I have a collision detection problem when the character moves right: Once the player moves right, whenever a new block is encountered, the player stops. I don't know if this is a problem with collision or the player but I can't work around it.

Here is the collision code:

this.IsColliding = function(obj) {
    if(this.X > obj.X + obj.Width) return false;
    else if(this.X + this.Width < obj.X) return false;
    else if(this.Y > obj.Y + obj.Height) return false;
    else if(this.Y + this.Height < obj.Y) return false;
    else return true;
}

I also wanted to see if there as a way to make the player collide with the bottom of the block and the right side of the block instead of running through it.

There is there the blocks connect and the player stops right at that moment.

© Game Development or respective owner

Related posts about collision-detection

Related posts about JavaScript