Results 1 to 5 of 5

Thread: Collision detection...how can this be done?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 1999
    Posts
    65

    Post

    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!"

  2. #2
    Lively Member
    Join Date
    Jun 1999
    Posts
    80

    Post

    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

  3. #3
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800

    Post

    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

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Oct 1999
    Posts
    65

    Post

    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!"

  5. #5
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800

    Post

    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).]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width