Skip to content

Commit

Permalink
feat: Transform origin and direction to account for level transformat…
Browse files Browse the repository at this point in the history
…ion (#405)
  • Loading branch information
mflerackers committed Sep 8, 2024
1 parent 9a108f8 commit 1bbf27e
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/game/level.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
vec2,
type Vec2Args,
} from "../math/math";
import { calcTransform } from "../math/various";
import type { CompList, GameObj, LevelComp, PathFindOpt } from "../types";
import { BinaryHeap } from "../utils";

Expand Down Expand Up @@ -351,6 +352,8 @@ export function addLevel(
}

obj.tilePos = p;
// Stale, so recalculate
obj.transform = calcTransform(obj);

if (spatialMap) {
insertIntoSpatialMap(obj);
Expand Down Expand Up @@ -412,7 +415,9 @@ export function addLevel(
return spatialMap![hash] || [];
},

raycast(origin: Vec2, direction: Vec2) {
raycast(this: GameObj<LevelComp | PosComp>, origin: Vec2, direction: Vec2) {
const worldOrigin = this.toWorld(origin);
const worldDirection = this.toWorld(origin.add(direction)).sub(worldOrigin);
const levelOrigin = origin.scale(
1 / this.tileWidth(),
1 / this.tileHeight(),
Expand All @@ -427,8 +432,8 @@ export function addLevel(
if (tile.is("area")) {
const shape = tile.worldArea();
const hit = shape.raycast(
origin,
direction,
worldOrigin,
worldDirection,
) as RaycastResult;
if (hit) {
if (minHit) {
Expand Down

0 comments on commit 1bbf27e

Please sign in to comment.