Collision detection

Hi,

I am trying to detect a collision between a character and an object.  I have it working to some extent as when the character collides with the left or right side it is detected.  However if the character tries to get over the object it also says that it has collided, even when it should clear it :-(

I have probably not explained this very well, so I have uploaded a .zip file at:

http://www.3doubleu.co.uk/game.zip

Thanks in advance,

John
LVL 14
john-formbyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jeff CertainCommented:
You need to check to see if the lower edge of the character also conflicts with the object.

If (character edges conflict) andalso (character bottom edge conflicts) then (kill character)
0
john-formbyAuthor Commented:
How do I define the edges?

0
Jeff CertainCommented:
image.bottom, image.left, image.left+image.width
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

john-formbyAuthor Commented:
I have tried that but it still doesn't work :-(  It detects collision but it appears as if the obstacle is right up to the top of the screen as even though he should clear it, he doesn't.
0
Jeff CertainCommented:
right... you need to check both the left/right AND the obstacle.top < character.bottom (b/c of the fact that higher on the screen is actually a lower number of pixels).

if you check  obstacle.top > character.bottom, your character will die when above the object.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
john-formbyAuthor Commented:
This is what I have:

If imgCharacter.Left + imgCharacter.Width > imgObstacle.Left And imgCharacter.Left < imgObstacle.Left + imgObstacle.Width Or imgCharacter.Top + imgCharacter.Height < imgObstacle.Top Then
            die()

I don't see what is wrong with it :-(
0
platinumbayCommented:
Try this:

    If ((imgPerson.Left + imgPerson.Width) > imgWall.Left) And _
                (imgPerson.Left < (imgWall.Left + imgWall.Width)) And _
                ((imgPerson.Top + imgPerson.Height) > imgWall.Top) Then
0
platinumbayCommented:
Sorry, I just got to work and I still had this window open, didn't see the other posts.
0
john-formbyAuthor Commented:
Thanks, that works great :-)

John
0
platinumbayCommented:
Chaosian should get the points though, he said the same thing I did.
0
john-formbyAuthor Commented:
You both deserve points.  I am awarding points for this question to Chaosian.  I have opened another question for you to collect your points, platinumbay at:

http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/VB_DOT_NET/Q_21219076.html

Thanks to both of you for your help,

John
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.