diff --git a/site/docs/07-actions/06.5-actions-meet.mdx b/site/docs/07-actions/06.5-actions-meet.mdx index b5cc4059..c8c32dda 100644 --- a/site/docs/07-actions/06.5-actions-meet.mdx +++ b/site/docs/07-actions/06.5-actions-meet.mdx @@ -8,6 +8,8 @@ section: Actions This method will cause the entity to move towards another until they are within 1 pixel of each other at a specified speed. +A tolerance optional parameter has been added to increase the range in which the Meet Action is completed. The default is still 1 pixel. + :::warning This action could possibly never complete! Any actions chained off of it will not fire until the target is met. You will need to call `.clearActions()` to schedule new actions. diff --git a/src/engine/Actions/Action/Meet.ts b/src/engine/Actions/Action/Meet.ts index 07e396e1..6828987f 100644 --- a/src/engine/Actions/Action/Meet.ts +++ b/src/engine/Actions/Action/Meet.ts @@ -21,8 +21,9 @@ export class Meet implements Action { private _started = false; private _stopped = false; private _speedWasSpecified = false; + private _tolerance = 1; - constructor(actor: Entity, actorToMeet: Entity, speed?: number) { + constructor(actor: Entity, actorToMeet: Entity, speed?: number, tolerance?: number) { this._tx = actor.get(TransformComponent); this._motion = actor.get(MotionComponent); this._meetTx = actorToMeet.get(TransformComponent); @@ -34,6 +35,10 @@ export class Meet implements Action { if (speed !== undefined) { this._speedWasSpecified = true; } + + if (tolerance !== undefined) { + this._tolerance = tolerance; + } } public update(elapsed: number): void { @@ -63,7 +68,7 @@ export class Meet implements Action { } public isComplete(): boolean { - return this._stopped || this._distanceBetween <= 1; + return this._stopped || this._distanceBetween <= this._tolerance; } public stop(): void { diff --git a/src/engine/Actions/ActionContext.ts b/src/engine/Actions/ActionContext.ts index 07eb9c41..da106551 100644 --- a/src/engine/Actions/ActionContext.ts +++ b/src/engine/Actions/ActionContext.ts @@ -544,12 +544,15 @@ export class ActionContext { * collide "meet" at a specified speed. * @param entity The entity to meet * @param speed The speed in pixels per second to move, if not specified it will match the speed of the other actor + * @param tolerance The tolerance in pixels to meet, if not specified it will be 1 pixel */ - public meet(entity: Entity, speed?: number): ActionContext { - if (speed === undefined) { + public meet(entity: Entity, speed?: number, tolerance?: number): ActionContext { + if (speed === undefined && tolerance === undefined) { this._queue.add(new Meet(this._entity, entity)); - } else { + } else if (tolerance === undefined) { this._queue.add(new Meet(this._entity, entity, speed)); + } else { + this._queue.add(new Meet(this._entity, entity, speed, tolerance)); } return this; }