Collision Detection VB.net (Help please)

Talk about your favorite PC games, Steam and building awesome custom rigs!

Moderator: Moderators

Post Reply
ghosstt
Senior Member
Posts: 1551
Joined: Mon Feb 26, 2007 4:14 pm

Collision Detection VB.net (Help please)

Post by ghosstt »

Im using this code to detect whether or not the player is touching the ground, and if it isn't, then it pulls it down till it does (to simulate gravity). The problem is that when it's in the aire, and hits the bottom of the "ground" object, it recalls the jump routine because it's hitting the ground. How can I do collision detection with just the top part of an object, not the whole thing?

Code: Select all

 
Private Sub PlayerGravity_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PlayerGravity.Tick
        If (Player.Bounds.IntersectsWith(Ground1.Bounds) = False) And (Player.Bounds.IntersectsWith(Ground1.Bounds) = False) And (Player.Bounds.IntersectsWith(Ground2.Bounds) = False) And (Player.Bounds.IntersectsWith(Ground3.Bounds) = False) And (Player.Bounds.IntersectsWith(Ground4.Bounds) = False) And (Player.Bounds.IntersectsWith(Ground5.Bounds) = False) And (Player.Bounds.IntersectsWith(Ground6.Bounds) = False) Then
            Player.Location = New Point((Player.Location.X), (Player.Location.Y + 1))
        End If
    End Sub
Post Reply