-
Feb 23rd, 2012, 01:01 PM
#1
Thread Starter
New Member
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.
-
Feb 23rd, 2012, 02:08 PM
#2
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|