I find these things are easier to tackle if you focus on the edge cases. For example, what do you want the density to be when a particle is motionless? By your original formula:
Density = 1.0 / Velocity.Magnitude (ie. Density = inverse Velocity).
If the particle has Velocity 0, you are going to get 1.0 / 0 = Infinity which Krakatoa isn’t going to handle particularly well. In particular, as the Velocity approaches 0, the Density will be getting larger and larger.
Here is an example solution:
InvVelocityToDensityKCM_example.zip (25.9 KB)