Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Time Factor for crowd agents update #12934

Merged
merged 1 commit into from
Sep 1, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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