Bullet path prediction (v0.0.10)


The Bullet Path Predictor is now online: this predictive system predicts your bullet's path with pinpoint accuracy.

See exactly where your shots will "land", especially when firing backwards from orbit.

Play Now!

Comments

Log in with itch.io to leave a comment.

Could you share some insights into the algorithm behind this incredible bullet prediction system with orbital influence? It's such an impressive feature—congratulations on creating such an amazing game!

Thanks so much! It uses a variant of the missile algorithm :) The game basically looks into the future by calculating where everything will be - both the enemy ships and where your bullet would go if you fired now - in a simplified gravity-only simulation. When it sees the paths cross, that's when your aiming line turns orange. (Sorry for the late reply, crunch time at work!)

How does it predict well where everything will be with the orbit logic? My prediction keeps getting small errors. 

The lower line is the prediction and the upper one is the real trajectory

My prediction code iterates over some X steps with a deltaTime to calculate where it should be. Could you share your prediction? It seems to work way better

(1 edit)

In general I think the predictor should mimic the physics engine as much as possible. For velocity & position, your Predict seems to be doing a variant of Størmer-Verlet, while (if you're on Unity) PhysX apparently does semi-implicit Euler, which my physics engine also uses, so that's what I use in my prediction code:

  1. forceAtPosition, acceleration as before
  2. currentVelocity += acceleration * deltaTime
  3. nextPosition = currentPosition + currentVelocity * deltaTime
  4. (assign nextPosition to positions[i], currentPosition)

Also make deltaTime the same as what PhysX uses. Oh and if your planets move, make sure to use their future (not current) position for the force (and if your planets also move under gravity... you need to predict everyone at the same time :) ).

Thank you so much for your response, Patrick! I truly appreciate your effort to help me, and I'm learning a lot through this process. Unfortunately, the issue still persists.

Unity 2D physics is based on  Box2D, which uses the same Semi-Implicit Euler integration you talked. I adjusted my algorithm to match this, but it didn't resolve the problem.

The main challenge lies in my virtual gravity algorithm. It calculates totalForceApplied as a vector and then applies it using Unity's AddForce method. However, AddForce only updates the Rigidbody's velocity in the next physics frame, which makes it unsuitable for immediate trajectory predictions.

Because of this limitation, I'm trying to simulate the physics myself. Despite my efforts, it hasn't been working, and I've been stuck on this for over a week.

I think it's best to take a break from this problem and focus on other tasks for now. Sometimes a fresh perspective helps! Thank you so much for your support—I truly appreciate it!

Piece of code showing how I manage the virtual gravity