mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-16 13:34:06 +09:00
somehow fixed but now jumping while walking against wall changes jump behav
This commit is contained in:
@@ -802,20 +802,13 @@ open class ActorWithBody : Actor {
|
|||||||
|
|
||||||
val stepBox = sixteenStep[step]
|
val stepBox = sixteenStep[step]
|
||||||
|
|
||||||
debug2("stepbox[$step]=$stepBox; feet?=${vectorSum.y > PHYS_EPSILON_DIST}")
|
val downDown = if (this is ActorHumanoid) this.isDownDown else false
|
||||||
|
val goingDown = (vectorSum.y > PHYS_EPSILON_DIST) || (vectorSum.y >= 0.0 && !isWalled(stepBox, if (gravitation.y >= 0.0) COLLIDING_BOTTOM else COLLIDING_TOP))
|
||||||
|
|
||||||
/*forEachOccupyingTilePos(stepBox) {
|
debug2("stepbox[$step]=$stepBox; goingDown=$goingDown, downDown=$downDown")
|
||||||
val tileCoord = LandUtil.resolveBlockAddr(world!!, it)
|
|
||||||
val tile = world!!.getTileFromTerrain(tileCoord.first, tileCoord.second) ?: Block.STONE
|
|
||||||
|
|
||||||
if (shouldICollideWithThis(tile) || (it.isFeetTile(stepBox) && shouldICollideWithThisFeet(tile))) {
|
// careful when using feet mode, as it will only look for collision on feet tiles!
|
||||||
collidingStep = step
|
if (isColliding(stepBox, goingDown && !downDown)) {
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
// trying to use same function as the others, in an effort to eliminate the "contradiction" mentioned below
|
|
||||||
if (isColliding(stepBox, vectorSum.y > PHYS_EPSILON_DIST)) {
|
|
||||||
// not registering collision sometimes?
|
|
||||||
collidingStep = step
|
collidingStep = step
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -826,24 +819,13 @@ open class ActorWithBody : Actor {
|
|||||||
var bounceY = false
|
var bounceY = false
|
||||||
var zeroX = false
|
var zeroX = false
|
||||||
var zeroY = false
|
var zeroY = false
|
||||||
// collision NOT detected
|
|
||||||
if (collidingStep == null) {
|
|
||||||
debug1("== Collision step: no collision")
|
|
||||||
hitbox.translate(vectorSum)
|
|
||||||
// grounded = false
|
|
||||||
}
|
|
||||||
// collision detected
|
|
||||||
else {
|
|
||||||
debug1("== Collision step: $collidingStep / $ccdSteps")
|
|
||||||
|
|
||||||
debug1("CCD hitbox: ${sixteenStep[collidingStep]}")
|
|
||||||
|
|
||||||
val newHitbox = hitbox.reassign(sixteenStep[collidingStep])
|
|
||||||
|
|
||||||
|
val newHitbox = if (collidingStep == null) null else hitbox.clone().reassign(sixteenStep[collidingStep])
|
||||||
var staircaseStatus = 0
|
var staircaseStatus = 0
|
||||||
var stairHeightLeft = 0.0
|
var stairHeightLeft = 0.0
|
||||||
var stairHeightRight = 0.0
|
var stairHeightRight = 0.0
|
||||||
val selfCollisionStatus = intArrayOf(1,2,4,8).fold(0) { acc, state ->
|
val selfCollisionStatus = if (newHitbox == null) 0 else
|
||||||
|
intArrayOf(1,2,4,8).fold(0) { acc, state ->
|
||||||
// also update staircaseStatus while we're iterating
|
// also update staircaseStatus while we're iterating
|
||||||
if (state and 5 != 0) {
|
if (state and 5 != 0) {
|
||||||
isWalledStairs(newHitbox, state).let {
|
isWalledStairs(newHitbox, state).let {
|
||||||
@@ -857,6 +839,19 @@ open class ActorWithBody : Actor {
|
|||||||
acc or (state * isWalledStairs(newHitbox, state).first.coerceAtMost(1))
|
acc or (state * isWalledStairs(newHitbox, state).first.coerceAtMost(1))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// collision NOT detected
|
||||||
|
if (collidingStep == null) {
|
||||||
|
debug1("== Collision step: no collision")
|
||||||
|
hitbox.translate(vectorSum)
|
||||||
|
// grounded = false
|
||||||
|
}
|
||||||
|
// collision detected
|
||||||
|
else {
|
||||||
|
debug1("== Collision step: $collidingStep / $ccdSteps")
|
||||||
|
debug1("CCD hitbox: ${sixteenStep[collidingStep]}")
|
||||||
|
|
||||||
|
val newHitbox = newHitbox!!
|
||||||
|
|
||||||
// superseded by isWalledStairs-related codes
|
// superseded by isWalledStairs-related codes
|
||||||
//if (isWalled(newHitbox, COLLIDING_LEFT)) selfCollisionStatus += COLL_LEFTSIDE // 1
|
//if (isWalled(newHitbox, COLLIDING_LEFT)) selfCollisionStatus += COLL_LEFTSIDE // 1
|
||||||
//if (isWalled(newHitbox, COLLIDING_BOTTOM)) selfCollisionStatus += COLL_BOTTOMSIDE // 2
|
//if (isWalled(newHitbox, COLLIDING_BOTTOM)) selfCollisionStatus += COLL_BOTTOMSIDE // 2
|
||||||
@@ -868,9 +863,9 @@ open class ActorWithBody : Actor {
|
|||||||
debug1("collision: $selfCollisionStatus\tstaircasing: $staircaseStatus")
|
debug1("collision: $selfCollisionStatus\tstaircasing: $staircaseStatus")
|
||||||
|
|
||||||
when (selfCollisionStatus) {
|
when (selfCollisionStatus) {
|
||||||
0 -> {
|
/*0 -> {
|
||||||
debug1("Contradiction -- collision detected by CCD, but isWalled() says otherwise")
|
debug1("Contradiction -- collision detected by CCD, but isWalled() says otherwise")
|
||||||
}
|
}*/
|
||||||
5 -> {
|
5 -> {
|
||||||
zeroX = true
|
zeroX = true
|
||||||
}
|
}
|
||||||
@@ -896,6 +891,11 @@ open class ActorWithBody : Actor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (selfCollisionStatus == 0) {
|
||||||
|
debug1("== selfCollisionStatus was zero, behaving as if (collidingStep = null)")
|
||||||
|
hitbox.translate(vectorSum)
|
||||||
|
}
|
||||||
|
else {
|
||||||
// fire Collision Event with one/two/three-side collision
|
// fire Collision Event with one/two/three-side collision
|
||||||
// for the ease of writing, this jumptable is separated from above.
|
// for the ease of writing, this jumptable is separated from above.
|
||||||
when (selfCollisionStatus) {
|
when (selfCollisionStatus) {
|
||||||
@@ -934,7 +934,6 @@ open class ActorWithBody : Actor {
|
|||||||
newHitbox.startY
|
newHitbox.startY
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
val angleOfIncidence =
|
val angleOfIncidence =
|
||||||
if (selfCollisionStatus in listOf(3, 9))
|
if (selfCollisionStatus in listOf(3, 9))
|
||||||
vectorSum.direction.toPositiveRad()
|
vectorSum.direction.toPositiveRad()
|
||||||
@@ -949,7 +948,13 @@ open class ActorWithBody : Actor {
|
|||||||
(Vector2(offendingHitboxPointX, offendingHitboxPointY) -
|
(Vector2(offendingHitboxPointX, offendingHitboxPointY) -
|
||||||
Vector2(offendingTileWorldX, offendingTileWorldY)).direction
|
Vector2(offendingTileWorldX, offendingTileWorldY)).direction
|
||||||
|
|
||||||
debug1("incidentAngle: ${Math.toDegrees(angleOfIncidence)}°, threshold: ${Math.toDegrees(angleThreshold)}°")
|
debug1(
|
||||||
|
"incidentAngle: ${Math.toDegrees(angleOfIncidence)}°, threshold: ${
|
||||||
|
Math.toDegrees(
|
||||||
|
angleThreshold
|
||||||
|
)
|
||||||
|
}°"
|
||||||
|
)
|
||||||
|
|
||||||
debug1("offendingTileWorldY=$offendingTileWorldY, offendingHitboxPointY=$offendingHitboxPointY")
|
debug1("offendingTileWorldY=$offendingTileWorldY, offendingHitboxPointY=$offendingHitboxPointY")
|
||||||
|
|
||||||
@@ -966,10 +971,25 @@ open class ActorWithBody : Actor {
|
|||||||
-vectorSum.signum
|
-vectorSum.signum
|
||||||
else {
|
else {
|
||||||
when (selfCollisionStatus) {
|
when (selfCollisionStatus) {
|
||||||
3 -> if (angleOfIncidence > angleThreshold) Vector2(1.0, 0.0) else Vector2(0.0, -1.0)
|
3 -> if (angleOfIncidence > angleThreshold) Vector2(1.0, 0.0)
|
||||||
6 -> if (angleOfIncidence > angleThreshold) Vector2(0.0, -1.0) else Vector2(-1.0, 0.0)
|
else Vector2(
|
||||||
|
0.0,
|
||||||
|
-1.0
|
||||||
|
)
|
||||||
|
|
||||||
|
6 -> if (angleOfIncidence > angleThreshold) Vector2(0.0, -1.0)
|
||||||
|
else Vector2(
|
||||||
|
-1.0,
|
||||||
|
0.0
|
||||||
|
)
|
||||||
|
|
||||||
9 -> if (angleOfIncidence > angleThreshold) Vector2(0.0, 1.0) else Vector2(1.0, 0.0)
|
9 -> if (angleOfIncidence > angleThreshold) Vector2(0.0, 1.0) else Vector2(1.0, 0.0)
|
||||||
12 -> if (angleOfIncidence > angleThreshold) Vector2(-1.0, 0.0) else Vector2(0.0, 1.0)
|
12 -> if (angleOfIncidence > angleThreshold) Vector2(-1.0, 0.0)
|
||||||
|
else Vector2(
|
||||||
|
0.0,
|
||||||
|
1.0
|
||||||
|
)
|
||||||
|
|
||||||
else -> throw InternalError("Blame hardware or universe")
|
else -> throw InternalError("Blame hardware or universe")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -988,14 +1008,17 @@ open class ActorWithBody : Actor {
|
|||||||
debug1("finalDisplacement=$finalDisplacement")
|
debug1("finalDisplacement=$finalDisplacement")
|
||||||
|
|
||||||
// adjust finalDisplacement for honest-to-god staircasing
|
// adjust finalDisplacement for honest-to-god staircasing
|
||||||
if (physProp.useStairs && vectorSum.y <= 0.0 && staircaseStatus in listOf(1, 4) && selfCollisionStatus in (if (gravitation.y >= 0.0) listOf(3,6) else listOf(9, 12))) {
|
if (physProp.useStairs && vectorSum.y <= 0.0 && staircaseStatus in listOf(1, 4) &&
|
||||||
|
selfCollisionStatus in (if (gravitation.y >= 0.0) listOf(3, 6) else listOf(9, 12))
|
||||||
|
) {
|
||||||
// remove Y displacement
|
// remove Y displacement
|
||||||
// let original X velocity to pass-thru instead of snapping to tiles coded above
|
// let original X velocity to pass-thru instead of snapping to tiles coded above
|
||||||
// pass-thru values are held by the vectorSum
|
// pass-thru values are held by the vectorSum
|
||||||
|
|
||||||
debug1("staircasing: $staircaseStatus for $selfCollisionStatus")
|
debug1("staircasing: $staircaseStatus for $selfCollisionStatus")
|
||||||
|
|
||||||
val stairHeight = if (staircaseStatus == COLLIDING_LEFT) stairHeightLeft else stairHeightRight
|
val stairHeight =
|
||||||
|
if (staircaseStatus == COLLIDING_LEFT) stairHeightLeft else stairHeightRight
|
||||||
finalDisplacement.y = -stairHeight
|
finalDisplacement.y = -stairHeight
|
||||||
finalDisplacement.x = vectorSum.x
|
finalDisplacement.x = vectorSum.x
|
||||||
|
|
||||||
@@ -1008,7 +1031,8 @@ open class ActorWithBody : Actor {
|
|||||||
// so we also zero the same exact value here for perfect hiding
|
// so we also zero the same exact value here for perfect hiding
|
||||||
if (controllerV != null) {
|
if (controllerV != null) {
|
||||||
val stairRatio = stairHeight / hitbox.height
|
val stairRatio = stairHeight / hitbox.height
|
||||||
stairPenaltyVector = Math.pow(1.0 - (stairRatio), 90 * stairRatio).times(10).coerceIn(0.00005, 1.0)
|
stairPenaltyVector =
|
||||||
|
Math.pow(1.0 - (stairRatio), 90 * stairRatio).times(10).coerceIn(0.00005, 1.0)
|
||||||
controllerV!!.x = 0.0
|
controllerV!!.x = 0.0
|
||||||
stairPenaltyCounter = 0
|
stairPenaltyCounter = 0
|
||||||
stairPenaltyMax = Math.pow(stairRatio, 2.4).times(166).roundToInt().coerceAtMost(64)
|
stairPenaltyMax = Math.pow(stairRatio, 2.4).times(166).roundToInt().coerceAtMost(64)
|
||||||
@@ -1031,7 +1055,6 @@ open class ActorWithBody : Actor {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// bounce X/Y
|
// bounce X/Y
|
||||||
if (bounceX) {
|
if (bounceX) {
|
||||||
externalV.x *= elasticity
|
externalV.x *= elasticity
|
||||||
@@ -1067,6 +1090,8 @@ open class ActorWithBody : Actor {
|
|||||||
|
|
||||||
// another platform-related hacks
|
// another platform-related hacks
|
||||||
if (this is ActorHumanoid) downDownVirtually = false
|
if (this is ActorHumanoid) downDownVirtually = false
|
||||||
|
|
||||||
|
}
|
||||||
}// end of collision not detected
|
}// end of collision not detected
|
||||||
|
|
||||||
|
|
||||||
@@ -1129,7 +1154,7 @@ open class ActorWithBody : Actor {
|
|||||||
/**
|
/**
|
||||||
* @see /work_files/hitbox_collision_detection_compensation.jpg
|
* @see /work_files/hitbox_collision_detection_compensation.jpg
|
||||||
*/
|
*/
|
||||||
private fun isColliding(hitbox: Hitbox, feet: Boolean = false): Boolean {
|
private fun isColliding(hitbox: Hitbox, usePlatformDetection: Boolean = false): Boolean {
|
||||||
if (isNoCollideWorld) return false
|
if (isNoCollideWorld) return false
|
||||||
|
|
||||||
// detectors are inside of the bounding box
|
// detectors are inside of the bounding box
|
||||||
@@ -1145,7 +1170,8 @@ open class ActorWithBody : Actor {
|
|||||||
val tyStart = y1/*.plus(HALF_PIXEL)*/.floorToInt()
|
val tyStart = y1/*.plus(HALF_PIXEL)*/.floorToInt()
|
||||||
val tyEnd = y2/*.plus(HALF_PIXEL)*/.floorToInt()
|
val tyEnd = y2/*.plus(HALF_PIXEL)*/.floorToInt()
|
||||||
|
|
||||||
return isCollidingInternalStairs(txStart, if (feet) tyEnd else tyStart, txEnd, tyEnd, feet).first > 0
|
// return isCollidingInternalStairs(txStart, if (feet) tyEnd else tyStart, txEnd, tyEnd, feet).first > 0
|
||||||
|
return isCollidingInternalStairs(txStart, tyStart, txEnd, tyEnd, usePlatformDetection).first > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1327,7 +1353,7 @@ open class ActorWithBody : Actor {
|
|||||||
var stairHeight = 0
|
var stairHeight = 0
|
||||||
var hitFloor = false
|
var hitFloor = false
|
||||||
|
|
||||||
if (ys.last != ys.first && feet) throw InternalError("Feet mode collision but pyStart != pyEnd ($pyStart .. $pyEnd)")
|
// if (ys.last != ys.first && feet) throw InternalError("Feet mode collision but pyStart != pyEnd ($pyStart .. $pyEnd)")
|
||||||
|
|
||||||
for (y in ys) {
|
for (y in ys) {
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user