somehow fixed but now jumping while walking against wall changes jump behav

This commit is contained in:
minjaesong
2023-08-11 01:04:34 +09:00
parent cef58f6a73
commit 579b6b5b29

View File

@@ -802,20 +802,13 @@ open class ActorWithBody : Actor {
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) {
val tileCoord = LandUtil.resolveBlockAddr(world!!, it)
val tile = world!!.getTileFromTerrain(tileCoord.first, tileCoord.second) ?: Block.STONE
debug2("stepbox[$step]=$stepBox; goingDown=$goingDown, downDown=$downDown")
if (shouldICollideWithThis(tile) || (it.isFeetTile(stepBox) && shouldICollideWithThisFeet(tile))) {
collidingStep = step
}
}*/
// 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?
// careful when using feet mode, as it will only look for collision on feet tiles!
if (isColliding(stepBox, goingDown && !downDown)) {
collidingStep = step
}
@@ -826,24 +819,13 @@ open class ActorWithBody : Actor {
var bounceY = false
var zeroX = 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 stairHeightLeft = 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
if (state and 5 != 0) {
isWalledStairs(newHitbox, state).let {
@@ -857,6 +839,19 @@ open class ActorWithBody : Actor {
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
//if (isWalled(newHitbox, COLLIDING_LEFT)) selfCollisionStatus += COLL_LEFTSIDE // 1
//if (isWalled(newHitbox, COLLIDING_BOTTOM)) selfCollisionStatus += COLL_BOTTOMSIDE // 2
@@ -868,9 +863,9 @@ open class ActorWithBody : Actor {
debug1("collision: $selfCollisionStatus\tstaircasing: $staircaseStatus")
when (selfCollisionStatus) {
0 -> {
/*0 -> {
debug1("Contradiction -- collision detected by CCD, but isWalled() says otherwise")
}
}*/
5 -> {
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
// for the ease of writing, this jumptable is separated from above.
when (selfCollisionStatus) {
@@ -934,7 +934,6 @@ open class ActorWithBody : Actor {
newHitbox.startY
val angleOfIncidence =
if (selfCollisionStatus in listOf(3, 9))
vectorSum.direction.toPositiveRad()
@@ -949,7 +948,13 @@ open class ActorWithBody : Actor {
(Vector2(offendingHitboxPointX, offendingHitboxPointY) -
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")
@@ -966,10 +971,25 @@ open class ActorWithBody : Actor {
-vectorSum.signum
else {
when (selfCollisionStatus) {
3 -> if (angleOfIncidence > angleThreshold) 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)
3 -> if (angleOfIncidence > angleThreshold) 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)
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")
}
}
@@ -988,14 +1008,17 @@ open class ActorWithBody : Actor {
debug1("finalDisplacement=$finalDisplacement")
// 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
// let original X velocity to pass-thru instead of snapping to tiles coded above
// pass-thru values are held by the vectorSum
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.x = vectorSum.x
@@ -1008,7 +1031,8 @@ open class ActorWithBody : Actor {
// so we also zero the same exact value here for perfect hiding
if (controllerV != null) {
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
stairPenaltyCounter = 0
stairPenaltyMax = Math.pow(stairRatio, 2.4).times(166).roundToInt().coerceAtMost(64)
@@ -1031,7 +1055,6 @@ open class ActorWithBody : Actor {
}
// bounce X/Y
if (bounceX) {
externalV.x *= elasticity
@@ -1067,6 +1090,8 @@ open class ActorWithBody : Actor {
// another platform-related hacks
if (this is ActorHumanoid) downDownVirtually = false
}
}// end of collision not detected
@@ -1129,7 +1154,7 @@ open class ActorWithBody : Actor {
/**
* @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
// detectors are inside of the bounding box
@@ -1145,7 +1170,8 @@ open class ActorWithBody : Actor {
val tyStart = y1/*.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 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) {