Collision bugs...Please help!

Dec 29, 2011 at 1:03 AM
Edited Dec 30, 2011 at 6:35 PM

Instead of creating a new thread, decided to revamp this one.

I have collision down and everything else figured out. My problem is for some reason, there is like a big, invisible box that blocks my sprite from moving. It covers part of the grass tiles and part of the water tiles.

Please ignore the sloppiness of my code, I plan to clean up later.

Could someone take a look and help me figure out where I'm going wrong?

What I'm trying to do is make the water tiles (Index of 12) blocking, but it's not working.

 

Here is my packaged solution in .rar format. Size is 128.27KB :

http://www.mediafire.com/?n4f4smkm2w0btuo

Dec 30, 2011 at 11:39 PM

I have realized it is drawing the 'blocking area' just a bit too far south.

I made an 'L' shape on a new map with water and I can follow it as compared to the water layout above it. How would I center it in the correct place?

Dec 31, 2011 at 10:34 AM

The problem is the collision detection code, you are always checking both horizontal and vertical collisions regardless if the player only moved in one direction, that caused some weird efects. Here is the fixed version:

http://dl.dropbox.com/u/19912093/Sprite.rar

I rewrote the collision detection code in a way that it checks every pixel depending on wich side the player moved. I also made some changues to the Game1.cs Update method to fix the positioning in case a collision occurs. =)

ps. English is not my native languaje so i may have some typo errors.

Dec 31, 2011 at 4:20 PM

Although I was not expecting a full solution to this problem, it works perfectly! I've just spent the past 20 minutes or so studying the collision code you wrote, so I can learn from this and my prior mistakes.

Thank you for your help! Everything else should be a piece of cake now =D

Dec 31, 2011 at 7:24 PM

You're welcome.  =)

Jan 29, 2012 at 6:41 PM

I like the code also, only thing different I do is rather than just check that the tile is water I have a collision property so I can have some water that can be moved into. I would modify the code something like this:

if (tile != null)

{

if (tile.TileIndex.Collidable == 1)

{

return true;

}

}