Archived

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

Collision Detection help PLZ!!!

This topic is 6199 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

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 on other sites
You''ve got to check x and y at the same time, then you can walk around the wall.

Share on other sites
How do I ckeck for x and y at the same time?

Share on other sites
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

1. 1
2. 2
3. 3
Rutin
19
4. 4
5. 5

• 10
• 14
• 30
• 13
• 11
• Forum Statistics

• Total Topics
631785
• Total Posts
3002348
×