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 From -60 to 12…Does anyone have an idea how I could check the collision in a cleaner or better way?
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 Oh and I don’t use Physics for them…They just have a linear velocity on the z axis.
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.