Collision Detection help PLZ!!!

Started by
2 comments, last by Rad76 22 years, 8 months ago
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.
Advertisement
You''ve got to check x and y at the same time, then you can walk around the wall.
How do I ckeck for x and y at the same time?
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

This topic is closed to new replies.

Advertisement