I'm making a top-down spaceship game (like Asteroids). But I'm struggling to understand the maximum velocity limitation of love.physics.
To move I apply a linear force, simulating the thrusters. I kind of learnt to live with the ship not accelerating beyond a certain velocity (after all, I don't want it to go infinitely fast anyway), but now the ship can't shoot properly anymore, because the bullets it fires won't go faster than the ship and just bumble along in front of it.
I can think of a few solutions but I don't like any of them and would like to know if there's a better or established way:
- Use kinematic sensors for the bullets (so they still report collisions) and move them manually, but this seems dirty and might lead to problems if there are a lot of bullets.
- Limit the speed of both ships and bullets to be lower than the maximum velocity, but this has its own problems:
- How exactly do I limit the velocity? Do I iterate over each body manually, check it's velocity and manually set it to something smaller? Do I apply force in the opposite direction? Friction?
- I can't predict the maximum velocity, because there are asteroids in the world and it seems to change wildly depending how many there are:
~500 Asteroids -> about 400 m/s
~2000 Asteroids -> about 200 m/s - The game's quite boring if things move too slow. I guess I need to adjust the scale of things to make them look faster, but then the velocity changes again
FYI:
- ships are 4 by 4.5 units and have a mass of 7
- bullets are 0.4 by 1.4 units and have a mass of 0.001
- asteroids are random size between 20 by 20 and 50 by 50 and have a mass between ~25 and ~250 when set to 'dynamic' body. I tried using kinematic bodies but that didn't help.
- 'meter' is set to 6 for drawing and 1 the rest of the time