Hi, I’m making a 3rd person shooter game, and some of the attacks involve shooting a quite large projectile fast. With the default fixed timestep (0.02), there were cases where the physics skip the collision, resulting in stuck objects or going through others.
My question is, how low could the fixed timestep be to keep the game running good on most computers? I’m my game, I think there are not a large number of projectiles, in the worst case, maybe 20 at the same time. Right now, I’ve lowered it to 0.01, but I don’t know if this is too low for some computers, or when the game becomes more advaced.
2 Answers
2Use a SphereCast and let it work out what the projectile will collide with. Fast moving objects need special attention from you. Work out where the projectile is now, and where it’ll be based on it’s velocity and your fixed timestep. Sweep the sphere along the line from those two positions. Then you’ll know if the projectile will hit anything. Obviously there is a possibility that the projectile will collide with something that is moving, so your test may give you false positives.
Make the fast moving objects (bullet) a rigidbody and set its Interpolate option to Interpolate, and the collision detection continuous dynamic. The rigidbody it collides with should also be set to this values.
With this options, the fast moving objects are simulated between the fixed timesteps, and the collisions should work just fine.
Yes, I know that sphere/ray casting is a good solution for the time between physic calculations, but I'm not exactly sure how to put that into physics. I mean, if I do a sphere cast between 2 positions, and it turns out to exist collision, how can I make the physics engine to know it and do the necessary calculations (bounce, etc)?
– Waliactico