mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-13 23:26:07 +09:00
improved collision displacer: no more clip-to-climb-up-rightside-only thingy
This commit is contained in:
@@ -430,7 +430,7 @@ class StateInGameGDX(val batch: SpriteBatch) : Screen {
|
|||||||
// blur lightmap //
|
// blur lightmap //
|
||||||
///////////////////
|
///////////////////
|
||||||
val blurIterations = 5 // ideally, 4 * radius; must be even/odd number -- odd/even number will flip the image
|
val blurIterations = 5 // ideally, 4 * radius; must be even/odd number -- odd/even number will flip the image
|
||||||
val blurRadius = 4f / lightmapDownsample // (3, 4f); using low numbers for pixel-y aesthetics
|
val blurRadius = 4f / lightmapDownsample // (5, 4f); using low numbers for pixel-y aesthetics
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -657,29 +657,42 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean
|
|||||||
|
|
||||||
// points to the EDGE of the tile in world dimension (don't use this directly to get tilewise coord!!)
|
// points to the EDGE of the tile in world dimension (don't use this directly to get tilewise coord!!)
|
||||||
val offendingTileWorldX = if (selfCollisionStatus in listOf(6, 12))
|
val offendingTileWorldX = if (selfCollisionStatus in listOf(6, 12))
|
||||||
newHitbox.endX.div(TILE_SIZE).floor() * TILE_SIZE
|
newHitbox.endX.div(TILE_SIZE).floor() * TILE_SIZE - 0.00001
|
||||||
else
|
else
|
||||||
newHitbox.startX.div(TILE_SIZE).ceil() * TILE_SIZE
|
newHitbox.startX.div(TILE_SIZE).ceil() * TILE_SIZE
|
||||||
|
|
||||||
// points to the EDGE of the tile in world dimension (don't use this directly to get tilewise coord!!)
|
// points to the EDGE of the tile in world dimension (don't use this directly to get tilewise coord!!)
|
||||||
val offendingTileWorldY = if (selfCollisionStatus in listOf(3, 6))
|
val offendingTileWorldY = if (selfCollisionStatus in listOf(3, 6))
|
||||||
newHitbox.endY.div(TILE_SIZE).floor() * TILE_SIZE
|
newHitbox.endY.div(TILE_SIZE).floor() * TILE_SIZE - 0.00001
|
||||||
else
|
else
|
||||||
newHitbox.startY.div(TILE_SIZE).ceil() * TILE_SIZE
|
newHitbox.startY.div(TILE_SIZE).ceil() * TILE_SIZE
|
||||||
|
|
||||||
val offendingHitboxPointX = if (selfCollisionStatus in listOf(6, 12))
|
val offendingHitboxPointX = if (selfCollisionStatus in listOf(6, 12))
|
||||||
newHitbox.endX
|
newHitbox.endX
|
||||||
else
|
else
|
||||||
newHitbox.startX
|
newHitbox.startX
|
||||||
|
|
||||||
val offendingHitboxPointY = if (selfCollisionStatus in listOf(3, 6))
|
val offendingHitboxPointY = if (selfCollisionStatus in listOf(3, 6))
|
||||||
newHitbox.endY
|
newHitbox.endY
|
||||||
else
|
else
|
||||||
newHitbox.startY
|
newHitbox.startY
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
val angleOfIncidence =
|
||||||
|
if (selfCollisionStatus in listOf(3, 9))
|
||||||
|
vectorSum.direction.toPositiveRad()
|
||||||
|
else
|
||||||
|
vectorSum.direction
|
||||||
|
|
||||||
|
val angleThreshold =
|
||||||
|
if (selfCollisionStatus in listOf(3, 9))
|
||||||
|
(Vector2(offendingHitboxPointX, offendingHitboxPointY) -
|
||||||
|
Vector2(offendingTileWorldX, offendingTileWorldY)).direction.toPositiveRad()
|
||||||
|
else
|
||||||
|
(Vector2(offendingHitboxPointX, offendingHitboxPointY) -
|
||||||
|
Vector2(offendingTileWorldX, offendingTileWorldY)).direction
|
||||||
|
|
||||||
val angleOfIncidence = vectorSum.direction.toPositiveRad()
|
|
||||||
val angleThreshold = (Vector2(offendingHitboxPointX, offendingHitboxPointY) -
|
|
||||||
Vector2(offendingTileWorldX, offendingTileWorldY)).direction.toPositiveRad()
|
|
||||||
|
|
||||||
|
|
||||||
val displacementAbs = Vector2(
|
val displacementAbs = Vector2(
|
||||||
@@ -688,9 +701,8 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
// conditions should be four? for 4 corners?
|
// FIXME jump-thru-ceil bug on 1px-wide (the edge), case-9 collision (does not occur on case-12 coll.)
|
||||||
// or mathe works regardless?
|
|
||||||
// (need to account for I < TH; I > TH; I == TH)
|
|
||||||
|
|
||||||
val displacementUnitVector =
|
val displacementUnitVector =
|
||||||
if (angleOfIncidence == angleThreshold)
|
if (angleOfIncidence == angleThreshold)
|
||||||
@@ -717,6 +729,8 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean
|
|||||||
newHitbox.translate(finalDisplacement)
|
newHitbox.translate(finalDisplacement)
|
||||||
|
|
||||||
|
|
||||||
|
// TODO: translate other axis proportionally to the incident vector
|
||||||
|
|
||||||
bounceX = angleOfIncidence == angleThreshold || displacementUnitVector.x != 0.0
|
bounceX = angleOfIncidence == angleThreshold || displacementUnitVector.x != 0.0
|
||||||
bounceY = angleOfIncidence == angleThreshold || displacementUnitVector.y != 0.0
|
bounceY = angleOfIncidence == angleThreshold || displacementUnitVector.y != 0.0
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user