Click to See Complete Forum and Search --> : Collision detection...how can this be done?
Apollo
Nov 12th, 1999, 06:22 AM
I need simple collision detection.
The user is limited to a certain amount of squares that they are allowed to walk on. If they go on to a non-walkonable square, such as...oh I don't know, a 120 foot tall solid steel chicken, they stop as if it were 3D.
Does anyone have even ONE way to do this.
------------------
"I'm carrying a Geometry book, but I'm not in Geometry...it's crazy...crazy man!"
cedx
Nov 12th, 1999, 06:30 AM
Here's a simple collision detection for two Images.
`Image1 is left of Image2.
`move Image1 to the right.
if ((Image1.left + Image1.width) >= Image2.left) then
`collison happened.
end if
You'll need to code this for all sides of the images.
HTH
SteveCRM
Nov 12th, 1999, 08:45 PM
Personally, I use this:
If Abs(Image1.Left - Image2.Left) < Image1.Width And Abs(Image1.Top - Image2.Top) < Image1.Height Then
your collision happens. This one might be longer, but you don't have to do it for all sides of the image.
Steve
Apollo
Nov 13th, 1999, 06:28 AM
What I really need is to check which side of the object the user hit. Top, bottom, left, right. Because the problem I am having now, is that (I used Steve's code BTW) all I can check for is if my character hit the image. Then I can do things. Like disable the user from going a certain direction, like up. The problem is that I have to check for the same condition (If the user hit the image) for all sides. So what ends up happening, is when the user steps up into the image, he can't continue up. But he cannot go down either. Or right, or left. I don't want to fix this. I just want to know if there is a method that can check which side of an object the user hit?
I'll probably end up using cedx's code though. So I'm not in any big rush to know.
------------------
"I'm carrying a Geometry book, but I'm not in Geometry...it's crazy...crazy man!"
SteveCRM
Nov 13th, 1999, 09:22 AM
The bad part about the code that I sent to you, is that it checks if the images are the same at the Top and Left. So if they are barely touching, say at the corners, it won't detect the collision. Sorry for any inconviniences.
Steve
[This message has been edited by SteveCRM (edited 11-13-1999).]
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.