Skip to content

Commit

Permalink
Merge pull request #12934 from CedricGuillemet/NavSpeedFactor
Browse files Browse the repository at this point in the history
Time Factor for crowd agents update

Former-commit-id: 0cd52d0bd7bc01a6115cb8f39e9f338475b675d9
  • Loading branch information
sebavan committed Sep 1, 2022
2 parents 5816220 + ff875a2 commit 7d041bd
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion packages/dev/core/src/Navigation/Plugins/recastJSPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export class RecastJSPlugin implements INavigationEnginePlugin {

private _maximumSubStepCount: number = 10;
private _timeStep: number = 1 / 60;
private _timeFactor: number = 1;

private _tempVec1: any;
private _tempVec2: any;
Expand Down Expand Up @@ -111,6 +112,22 @@ export class RecastJSPlugin implements INavigationEnginePlugin {
return this._maximumSubStepCount;
}

/**
* Time factor applied when updating crowd agents (default 1). A value of 0 will pause crowd updates.
* @param value the time factor applied at update
*/
public set timeFactor(value: number) {
this._timeFactor = Math.max(value, 0);
}

/**
* Get the time factor used for crowd agent update
* @returns the time factor
*/
public get timeFactor(): number {
return this._timeFactor;
}

/**
* Creates a navigation mesh
* @param meshes array of all the geometry used to compute the navigation mesh
Expand Down Expand Up @@ -547,7 +564,7 @@ export class RecastJSCrowd implements ICrowd {
this._scene = scene;

this._onBeforeAnimationsObserver = scene.onBeforeAnimationsObservable.add(() => {
this.update(scene.getEngine().getDeltaTime() * 0.001);
this.update(scene.getEngine().getDeltaTime() * 0.001 * plugin.timeFactor);
});
}

Expand Down Expand Up @@ -750,6 +767,10 @@ export class RecastJSCrowd implements ICrowd {
update(deltaTime: number): void {
// update obstacles
this.bjsRECASTPlugin.navMesh.update();

if (deltaTime <= Epsilon) {
return;
}
// update crowd
const timeStep = this.bjsRECASTPlugin.getTimeStep();
const maxStepCount = this.bjsRECASTPlugin.getMaximumSubStepCount();
Expand Down

0 comments on commit 7d041bd

Please sign in to comment.