mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-17 00:56:07 +09:00
another wip
This commit is contained in:
@@ -481,7 +481,7 @@ open class ActorWithBody : Actor {
|
|||||||
* @param acc acceleration in Vector2, the unit is [px / InternalFrame^2]
|
* @param acc acceleration in Vector2, the unit is [px / InternalFrame^2]
|
||||||
*/
|
*/
|
||||||
fun applyAcceleration(acc: Vector2) {
|
fun applyAcceleration(acc: Vector2) {
|
||||||
externalV += acc * speedMultByTile
|
externalV += acc
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun Vector2.applyViscoseDrag() {
|
private fun Vector2.applyViscoseDrag() {
|
||||||
@@ -584,11 +584,11 @@ open class ActorWithBody : Actor {
|
|||||||
// printdbg(this, "BodyViscosity=$bodyViscosity FeetViscosity=$feetViscosity BodyFriction=$bodyFriction FeetFriction=$feetFriction")
|
// printdbg(this, "BodyViscosity=$bodyViscosity FeetViscosity=$feetViscosity BodyFriction=$bodyFriction FeetFriction=$feetFriction")
|
||||||
// }
|
// }
|
||||||
|
|
||||||
externalV.applyViscoseDrag()
|
// externalV.applyViscoseDrag()
|
||||||
|
|
||||||
// controllerV?.let {
|
controllerV?.let {
|
||||||
// it.applyViscoseDrag()
|
it.applyViscoseDrag()
|
||||||
// }
|
}
|
||||||
|
|
||||||
val vecSum = (externalV + (controllerV ?: Vector2(0.0, 0.0)))
|
val vecSum = (externalV + (controllerV ?: Vector2(0.0, 0.0)))
|
||||||
/**
|
/**
|
||||||
@@ -653,7 +653,7 @@ open class ActorWithBody : Actor {
|
|||||||
|
|
||||||
// --> Apply more forces <-- //
|
// --> Apply more forces <-- //
|
||||||
// Actors are subject to the gravity and the buoyancy if they are not levitating
|
// Actors are subject to the gravity and the buoyancy if they are not levitating
|
||||||
val buoyancy = applyBuoyancy() * speedMultByTile
|
val buoyancy = applyBuoyancy()
|
||||||
if (!isNoSubjectToGrav) {
|
if (!isNoSubjectToGrav) {
|
||||||
hitbox.translate(buoyancy)
|
hitbox.translate(buoyancy)
|
||||||
clampHitbox()
|
clampHitbox()
|
||||||
@@ -1681,11 +1681,11 @@ open class ActorWithBody : Actor {
|
|||||||
if (world == null) return Vector2()
|
if (world == null) return Vector2()
|
||||||
|
|
||||||
val rho = tileDensityFluid // kg / m^3
|
val rho = tileDensityFluid // kg / m^3
|
||||||
// V = submergedHeight in meters * f(object density)
|
val V_full = mass / density // density = mass / volume, simply rearrange this
|
||||||
val V = mass * density // m^3
|
val V = V_full * submergedRatio
|
||||||
val g = world!!.gravitation // m / s^2
|
val g = world!!.gravitation // m / s^2
|
||||||
val F_k = g * mass // Newtons = kg * m / s^2
|
val F_k = g * mass // Newtons = kg * m / s^2
|
||||||
val F_bo = (g * mass) * (rho / density) * submergedRatio
|
val F_bo = g * (rho * V) // Newtons
|
||||||
|
|
||||||
// mh'' = mg - rho*gv
|
// mh'' = mg - rho*gv
|
||||||
// h'' = (mg - rho*gv) / m
|
// h'' = (mg - rho*gv) / m
|
||||||
|
|||||||
@@ -866,7 +866,6 @@ object IngameRenderer : Disposable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private val bodyFriction = BlockCodex[Block.AIR].friction.frictionToMult()
|
private val bodyFriction = BlockCodex[Block.AIR].friction.frictionToMult()
|
||||||
private val bodyViscosity = FluidCodex[Block.AIR].viscosity.viscosityToMult()
|
|
||||||
|
|
||||||
|
|
||||||
private fun applyGravitation(gravitation: Vector2, hitboxWidth: Double) {
|
private fun applyGravitation(gravitation: Vector2, hitboxWidth: Double) {
|
||||||
@@ -877,8 +876,7 @@ object IngameRenderer : Disposable {
|
|||||||
private fun Int.viscosityToMult(): Double = 16.0 / (16.0 + this)
|
private fun Int.viscosityToMult(): Double = 16.0 / (16.0 + this)
|
||||||
|
|
||||||
private fun applyForce(acc: Vector2) {
|
private fun applyForce(acc: Vector2) {
|
||||||
val speedMultByTile = bodyViscosity
|
externalV += acc
|
||||||
externalV += acc * speedMultByTile
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getDrag(externalForce: Vector2, gravitation: Vector2, hitboxWidth: Double): Vector2 {
|
private fun getDrag(externalForce: Vector2, gravitation: Vector2, hitboxWidth: Double): Vector2 {
|
||||||
|
|||||||
@@ -499,7 +499,7 @@ open class ActorHumanoid : ActorWithBody, Controllable, Pocketed, Factionable, L
|
|||||||
else {
|
else {
|
||||||
isWalkingH = true
|
isWalkingH = true
|
||||||
|
|
||||||
readonly_totalX =
|
readonly_totalX = speedMultByTile *
|
||||||
if (absAxisVal == AXIS_KEYBOARD)
|
if (absAxisVal == AXIS_KEYBOARD)
|
||||||
avAcceleration * applyVelo(walkCounterX) * (if (left) -1f else 1f)
|
avAcceleration * applyVelo(walkCounterX) * (if (left) -1f else 1f)
|
||||||
else
|
else
|
||||||
|
|||||||
Reference in New Issue
Block a user