diff --git a/engine/system/physics.ts b/engine/system/physics.ts index 69edbaa..ce42069 100644 --- a/engine/system/physics.ts +++ b/engine/system/physics.ts @@ -7,6 +7,7 @@ import { getDistance, getDotProduct, invScale, + scale, setUnitNormal, type Vector, } from "#/engine/Vector.ts"; @@ -283,8 +284,17 @@ export function moveAndSlide( ): void { const collisions = moveAndCollide(id, velocity, delta); for (const collision of collisions) { + const time = collision.time; + if (time === -Infinity) { + continue; // TODO + } const dot = getDotProduct(velocity, collision.normal); - velocity.x -= collision.normal.x * dot; - velocity.y -= collision.normal.y * dot; + const ts = Math.min(0, time - 0.001); + const tsx = velocity.x * ts; + const tsy = velocity.y * ts; + const rt = 1 - time; + + velocity.x -= collision.normal.x * dot * rt + tsx; + velocity.y -= collision.normal.y * dot * rt + tsy; } } diff --git a/game/entities/hero/entity.ts b/game/entities/hero/entity.ts index d38b781..de1ae9a 100644 --- a/game/entities/hero/entity.ts +++ b/game/entities/hero/entity.ts @@ -1,6 +1,5 @@ import { defineEntity } from "#/engine/Entity.ts"; import { keyboardInput } from "#/engine/Keyboard.ts"; -import { lerp } from "#/engine/lib/lerp"; import { pointer } from "#/engine/Pointer.ts"; import { createRect, fillRect, strokeRect } from "#/engine/Rect.ts"; import $ from "#/engine/Scene.ts"; @@ -11,15 +10,12 @@ import { } from "#/engine/Sprite.ts"; import { type Collider, - type Collision, createCollider, - moveAndCollide, moveAndSlide, Shape, } from "#/engine/system/physics.ts"; import { createVector, - getDotProduct, normalize, scale, type Vector, diff --git a/game/scenes/testScene/data.json b/game/scenes/testScene/data.json index e52001d..8396e84 100644 --- a/game/scenes/testScene/data.json +++ b/game/scenes/testScene/data.json @@ -12,6 +12,15 @@ } } }, + { + "name": "portal", + "init": { + "position": { + "x": 24, + "y": 41 + } + } + }, { "name": "portal", "init": {