mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 12:21:52 +09:00
separate external velocity and acceleration, still broken
This commit is contained in:
@@ -114,6 +114,8 @@ open class ActorWBMovable(renderOrder: RenderOrder, val immobileBody: Boolean =
|
|||||||
*/
|
*/
|
||||||
internal val externalV = Vector2(0.0, 0.0)
|
internal val externalV = Vector2(0.0, 0.0)
|
||||||
|
|
||||||
|
internal val externalA = Vector2(0.0, 0.0)
|
||||||
|
|
||||||
@Transient private val VELO_HARD_LIMIT = 100.0
|
@Transient private val VELO_HARD_LIMIT = 100.0
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -223,7 +225,7 @@ open class ActorWBMovable(renderOrder: RenderOrder, val immobileBody: Boolean =
|
|||||||
* meter to pixel : 24/FPS
|
* meter to pixel : 24/FPS
|
||||||
*/
|
*/
|
||||||
private val gravitation: Vector2
|
private val gravitation: Vector2
|
||||||
get() = world?.gravitation ?: Vector2(0.0, 0.36)
|
get() = world?.gravitation ?: Vector2(0.0, 0.31)
|
||||||
@Transient val DRAG_COEFF_DEFAULT = 1.2
|
@Transient val DRAG_COEFF_DEFAULT = 1.2
|
||||||
/** Drag coefficient. Parachutes have much higher value than bare body (1.2) */
|
/** Drag coefficient. Parachutes have much higher value than bare body (1.2) */
|
||||||
var dragCoefficient: Double
|
var dragCoefficient: Double
|
||||||
@@ -353,7 +355,7 @@ open class ActorWBMovable(renderOrder: RenderOrder, val immobileBody: Boolean =
|
|||||||
* @param acc : Acceleration in Vector2
|
* @param acc : Acceleration in Vector2
|
||||||
*/
|
*/
|
||||||
fun applyForce(acc: Vector2) {
|
fun applyForce(acc: Vector2) {
|
||||||
externalV += acc * speedMultByTile
|
externalA += acc
|
||||||
}
|
}
|
||||||
|
|
||||||
private val bounceDampenVelThreshold = 0.5
|
private val bounceDampenVelThreshold = 0.5
|
||||||
@@ -545,7 +547,10 @@ open class ActorWBMovable(renderOrder: RenderOrder, val immobileBody: Boolean =
|
|||||||
|
|
||||||
if (!isNoSubjectToGrav && !(gravitation.y > 0 && walledBottom || gravitation.y < 0 && walledTop)) {
|
if (!isNoSubjectToGrav && !(gravitation.y > 0 && walledBottom || gravitation.y < 0 && walledTop)) {
|
||||||
//applyForce(getDrag(delta, externalV))
|
//applyForce(getDrag(delta, externalV))
|
||||||
applyForce(gravitation)
|
|
||||||
|
//applyForce(gravitation)
|
||||||
|
|
||||||
|
applyForce(Vector2(0.0, 0.01))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -650,7 +655,10 @@ open class ActorWBMovable(renderOrder: RenderOrder, val immobileBody: Boolean =
|
|||||||
// v(t) = v_0 + at
|
// v(t) = v_0 + at
|
||||||
// v_0 = myV
|
// v_0 = myV
|
||||||
val t = (Terrarum.PHYS_REF_FPS * delta)
|
val t = (Terrarum.PHYS_REF_FPS * delta)
|
||||||
val displacement = (externalV + (controllerMoveV ?: nullVec)) * t
|
val v0 = externalV + (controllerMoveV ?: nullVec)
|
||||||
|
val vt = v0 + externalA * t
|
||||||
|
val displacement = (v0 + vt) * 0.5 * t
|
||||||
|
externalV += externalA * t
|
||||||
val ccdSteps = minOf(16, (displacement.magnitudeSquared / TILE_SIZE.sqr()).floorInt() + 1) // adaptive
|
val ccdSteps = minOf(16, (displacement.magnitudeSquared / TILE_SIZE.sqr()).floorInt() + 1) // adaptive
|
||||||
|
|
||||||
|
|
||||||
@@ -851,18 +859,22 @@ open class ActorWBMovable(renderOrder: RenderOrder, val immobileBody: Boolean =
|
|||||||
// bounce X/Y
|
// bounce X/Y
|
||||||
if (bounceX) {
|
if (bounceX) {
|
||||||
externalV.x *= elasticity
|
externalV.x *= elasticity
|
||||||
|
externalA.x *= elasticity
|
||||||
controllerMoveV?.let { controllerMoveV!!.x *= elasticity }
|
controllerMoveV?.let { controllerMoveV!!.x *= elasticity }
|
||||||
}
|
}
|
||||||
if (bounceY) {
|
if (bounceY) {
|
||||||
externalV.y *= elasticity
|
externalV.y *= elasticity
|
||||||
|
externalA.y *= elasticity
|
||||||
controllerMoveV?.let { controllerMoveV!!.y *= elasticity }
|
controllerMoveV?.let { controllerMoveV!!.y *= elasticity }
|
||||||
}
|
}
|
||||||
if (zeroX) {
|
if (zeroX) {
|
||||||
externalV.x = 0.0
|
externalV.x = 0.0
|
||||||
|
externalA.x = 0.0
|
||||||
controllerMoveV?.let { controllerMoveV!!.x = 0.0 }
|
controllerMoveV?.let { controllerMoveV!!.x = 0.0 }
|
||||||
}
|
}
|
||||||
if (zeroY) {
|
if (zeroY) {
|
||||||
externalV.y = 0.0
|
externalV.y = 0.0
|
||||||
|
externalA.y = 0.0
|
||||||
controllerMoveV?.let { controllerMoveV!!.y = 0.0 }
|
controllerMoveV?.let { controllerMoveV!!.y = 0.0 }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ open class GameWorld {
|
|||||||
//public World physWorld = new World( new Vec2(0, -Terrarum.game.gravitationalAccel) );
|
//public World physWorld = new World( new Vec2(0, -Terrarum.game.gravitationalAccel) );
|
||||||
//physics
|
//physics
|
||||||
/** Some arbitrary and empirical value */
|
/** Some arbitrary and empirical value */
|
||||||
var gravitation: Vector2 = Vector2(0.0, 0.36)
|
var gravitation: Vector2 = Vector2(0.0, 0.31)
|
||||||
/** 0.0..1.0+ */
|
/** 0.0..1.0+ */
|
||||||
var globalLight = Color(0f,0f,0f,0f)
|
var globalLight = Color(0f,0f,0f,0f)
|
||||||
var averageTemperature = 288f // 15 deg celsius; simulates global warming
|
var averageTemperature = 288f // 15 deg celsius; simulates global warming
|
||||||
|
|||||||
Reference in New Issue
Block a user