diff --git a/src/engine/actions/action-context.ts b/src/engine/actions/action-context.ts index 2c1210b9..7648ea02 100644 --- a/src/engine/actions/action-context.ts +++ b/src/engine/actions/action-context.ts @@ -34,6 +34,7 @@ import type { CurveToOptions } from './action/curve-to'; import { CurveTo } from './action/curve-to'; import type { CurveByOptions } from './action/curve-by'; import { CurveBy } from './action/curve-by'; +import { Logger } from '../util'; /** * The fluent Action API allows you to perform "actions" on @@ -531,6 +532,10 @@ export class ActionContext { * @param followDistance The distance to maintain when following, if not specified the actor will follow at the current distance. */ public follow(entity: Entity, followDistance?: number): ActionContext { + if (!entity) { + Logger.getInstance().warn(`Entity does not exist when calling .follow() action`); + return this; + } if (followDistance === undefined) { this._queue.add(new Follow(this._entity, entity)); } else { @@ -547,6 +552,10 @@ export class ActionContext { * @param tolerance The tolerance in pixels to meet, if not specified it will be 1 pixel */ public meet(entity: Entity, speed?: number, tolerance?: number): ActionContext { + if (!entity) { + Logger.getInstance().warn(`Entity does not exist when calling .meet() action`); + return this; + } if (speed === undefined && tolerance === undefined) { this._queue.add(new Meet(this._entity, entity)); } else if (tolerance === undefined) { diff --git a/src/engine/actions/action/follow.ts b/src/engine/actions/action/follow.ts index 77bc6892..470e8799 100644 --- a/src/engine/actions/action/follow.ts +++ b/src/engine/actions/action/follow.ts @@ -35,6 +35,10 @@ export class Follow implements Action { } public update(elapsed: number): void { + if (!this._followTx || !this._followMotion) { + this.stop(); + return; + } if (!this._started) { this._started = true; this._distanceBetween = this._current.distance(this._end); diff --git a/src/engine/actions/action/meet.ts b/src/engine/actions/action/meet.ts index e78c6cd9..1da678a4 100644 --- a/src/engine/actions/action/meet.ts +++ b/src/engine/actions/action/meet.ts @@ -26,8 +26,10 @@ export class Meet implements Action { constructor(actor: Entity, actorToMeet: Entity, speed?: number, tolerance?: number) { this._tx = actor.get(TransformComponent); this._motion = actor.get(MotionComponent); + this._meetTx = actorToMeet.get(TransformComponent); this._meetMotion = actorToMeet.get(MotionComponent); + this._current = new Vector(this._tx.pos.x, this._tx.pos.y); this._end = new Vector(this._meetTx.pos.x, this._meetTx.pos.y); this._speed = speed || 0; @@ -42,6 +44,11 @@ export class Meet implements Action { } public update(elapsed: number): void { + if (!this._meetTx || !this._meetMotion) { + this.stop(); + return; + } + if (!this._started) { this._started = true; this._distanceBetween = this._current.distance(this._end);