CollisionCheck with several models

Hey guys!

I’m working on my Space Shooter right now where a spaceship is flying through many asteroids. Now I want to check if there is a collision between the ship and one of them. I tried to check if there are any CollisionResults with Ship.collideWith(asteroid.get(i).getWorldBound(), results); but this is insanely dropping my framerate :open_mouth: From -60 to 12…Does anyone have an idea how I could check the collision in a cleaner or better way?

Thanks :slight_smile:

Is this because you have many asteroids? What about if you compare it with the bounding box/sphere of the ship? (you ship may be very detailed) alternatively you can use GhostControls, but these also use AABB

Yep, i have many of them but they are removed when they are behind the ship…without this asteroid.getWorldBounds() the framerate is finde…But when I add this statement it litterally crashes :open_mouth: Oh and I don’t use Physics for them…They just have a linear velocity on the z axis.

You don’t need physics, you can just use them for collision detection

What @Wezrule said : Just prunes out your asteroid field based on location. This way you only check for collision with asteroids close enough.

You could also check if batching your asteroids enhance your framerate…

Are you iterating over all asteroids that are in the scene?
In that case, you could enter the asteroid objects into a SortedMap that’s ordered by Z coordinate. Then don’t iterate over all asteroids, just those that are in the collision-endangered Z coordinate zone, cutting down the collision-checking overhead to a fraction of what you do now.