Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Collision of object arrays question

$
0
0
Hi,

I'm working in a simple physics simulation game, but my only problem is when i try to calculate the collision of each object in the arraylist.
In other sites, i found few other solutions like this:

For ItemA = 0 to 59
    For ItemB = ItemA to 60
        'Checkcollision here!
    Next
Next



but when i try to put this on my code, i get a OutOfRange exception...

I tried to make the program obtain an item behind the current, so I tried to do the collision check from the two objects. the current and the previous to the current one.
But doesn't worked so good, the objects only collided with the floor.

Here is the code responsible for updating objects (in my case, particles):
'This code is part of the xWorld class.
Public Sub UpdateWorld(ByVal g As Graphics)

        For i As Integer = 0 To particles.Count - 1 
            Dim p As Particle = particles(i)

            If p.particle_type = PType.Powder Then
                g.FillRectangle(Brushes.Red, p.particle_X, p.particle_Y, gridsize, gridsize)

                'Here is the code responsible for updating the objects
                p.particle_yVel += gravity
                p.particle_yVel *= friction
                
                p.particle_Y += p.particle_yVel

                'snap to grid
                Dim iy As Integer = CInt(p.particle_Y / gridsize)
                p.particle_Y = iy * gridsize

            ElseIf p.particle_type = PType.Solid Then
                g.FillRectangle(Brushes.Gray, p.particle_X, p.particle_Y, gridsize, gridsize)
            End If
        Next

    End Sub



what I want is that the objects collide with each other, only the type of Powder and Solid
I had already achieved a similar type of collision, but it was not used an array.

Thanks for help. :smile2:/>

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>