swiming control

This commit is contained in:
minjaesong
2024-07-21 20:22:54 +09:00
parent 42b3b9e02f
commit 3386cfbd46
2 changed files with 63 additions and 10 deletions

View File

@@ -1622,12 +1622,18 @@ open class ActorWithBody : Actor {
private fun applyBuoyancy() {
if (world == null) return
// this term allows swimming. Model: you're opening a thruster pointing downwards
val jumpAcc = if (this is ActorHumanoid)
Vector2(0.0, swimAcc)
else
Vector2()
val rho = tileDensityFluid // kg / m^3
val V_full = mass / density * 2.0 // density = mass / volume, simply rearrange this. Multiplier of 2.0 is a hack!
val V = V_full * submergedRatio
val g = world!!.gravitation // m / s^2
val F_k = g * mass // Newtons = kg * m / s^2
val F_bo = g * (rho * V) // Newtons
val grav = world!!.gravitation // m / s^2
val F_k = (grav + jumpAcc) * mass // F = ma where a is g; TODO add jump-accel into 'a' to allow better jumping under water
val F_bo = grav * (rho * V) // Newtons
// mh'' = mg - rho*gv
// h'' = (mg - rho*gv) / m