Archived

This topic is now archived and is closed to further replies.

Rad76

Collision Detection help PLZ!!!

Recommended Posts

Rad76    122
Sorry for so many questions but I am making a game and here is how I did it, First I made 2 types like this: Public Type aMan x As Integer y As Integer End Type Public Type aWall x As Integer y As Integer End Type public Man as aMan public Wall as aWall Then I loaded in my pictures and displayed them on the screen with the PaintPicture method. What I want to do now is detect collsion between my person and the wall if I do this : If man.x <= wall.x then man.x = man.x - 200 it kind of works but even when I go around the wall it stops me. Anybody know a way I can detect just the wall and not the whole row? Thanks a lot.

Share this post


Link to post
Share on other sites
Nairb    766
This looks like you''re doing it in VB or QB, so that''s what I''ll be responding in...
First, add two things to your man and your wall: a width and a height that describes their size.
Then:

IF ( man.x + man.width >= wall.x AND_
man.x <= wall.x + wall.width AND_
man.y + man.height >= wall.y AND_
man.y <= wall.y + wall.height )
THEN
collision = true;

( the _ in the code denotes a continuation to the next line...
if you''re doing this in QB, you''ll have to put it all on
the same line, but I THINK that will work in VB ).

This will test the "bounding boxes" to see if they collide.
Once you know if there''s a collision, you can determine which direction the collision is taking place in and prevent the character from moving any further in that direction.
It may not be the best way, but it should work. :-D

--Nairb

Share this post


Link to post
Share on other sites