?
Solved

Collision detection

Posted on 2004-11-24
11
Medium Priority
?
202 Views
Last Modified: 2010-04-23
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
0
Comment
Question by:john-formby
  • 5
  • 3
  • 3
11 Comments
 
LVL 24

Expert Comment

by:Jeff Certain
ID: 12666374
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
 
LVL 14

Author Comment

by:john-formby
ID: 12666686
How do I define the edges?

0
 
LVL 24

Expert Comment

by:Jeff Certain
ID: 12666733
image.bottom, image.left, image.left+image.width
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 14

Author Comment

by:john-formby
ID: 12666816
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
 
LVL 24

Accepted Solution

by:
Jeff Certain earned 2000 total points
ID: 12666858
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
 
LVL 14

Author Comment

by:john-formby
ID: 12666934
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
 
LVL 6

Expert Comment

by:platinumbay
ID: 12667043
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
 
LVL 6

Expert Comment

by:platinumbay
ID: 12667068
Sorry, I just got to work and I still had this window open, didn't see the other posts.
0
 
LVL 14

Author Comment

by:john-formby
ID: 12667265
Thanks, that works great :-)

John
0
 
LVL 6

Expert Comment

by:platinumbay
ID: 12667325
Chaosian should get the points though, he said the same thing I did.
0
 
LVL 14

Author Comment

by:john-formby
ID: 12667404
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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Screencast - Getting to Know the Pipeline
Suggested Courses

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question