Results 1 to 2 of 2

Thread: Problems with collision detection

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2012
    Posts
    1

    Smile Problems with collision detection

    Let me just start off saying that I'm generally new to all programming so if my coding is painful to read I understand. I am currently working on a project that relies on perfect or near perfect collision detection, and I'm not sure whats wrong but sometimes the object being moved completly passes through the object it is supposed to collide at. Here's my coding relating to collision detection so far:

    Function xdetect(ByVal ObjA As Object, ByVal ObjB As Object)
    If (ObjA.Bounds.Right < ObjB.Bounds.Right _
    And _
    ObjA.Bounds.Right > ObjB.Bounds.Left) _
    Or _
    (ObjA.Bounds.Left < ObjB.Bounds.Right _
    And _
    ObjA.Bounds.Left > ObjB.Bounds.Left) Then
    Return True
    End If
    Return False
    End Function

    Function ydetect(ByVal ObjA As Object, ByVal ObjB As Object)
    If (ObjA.Bounds.top > ObjB.Bounds.top _
    And _
    ObjA.Bounds.top < ObjB.Bounds.bottom) _
    Or _
    (ObjA.Bounds.bottom > ObjB.Bounds.top _
    And _
    ObjA.Bounds.bottom < ObjB.Bounds.bottom) Then
    Return True
    End If
    Return False
    End Function

    And the coding that's for collisions:

    If xdetect(toon, ground) And
    ydetect(toon, ground) Then
    End If

    Also, the object, toon, is set to jump with a timer at an interval of 45. Any input regarding how I could make the overall collsion detection better or if I didnt provide the right section of code let me know.

    Any and all help appreciated.

  2. #2
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,601

    Re: Problems with collision detection

    The Rectangle structure has an IntersectsWith method that you can use to detect collision.

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