src/entities/Enemy.js
/**
	* Ensures the enemy never leaves the level.
	*
	* @return {Enemy} A reference to this game entity.
	*/
Ensures the enemy never leaves the level.
@return {Enemy} A reference to this game entity.
Ensures the enemy never leaves the level . @return { Enemy } A reference to this game entity .
stayInLevel() {
		this.currentPosition.copy( this.position );
		this.currentRegion = this.world.navMesh.clampMovement(
			this.currentRegion,
			this.previousPosition,
			this.currentPosition,
			this.position 
		);
		this.previousPosition.copy( this.position );
		const distance = this.currentRegion.plane.distanceToPoint( this.position );
		this.position.y -= distance * CONFIG.NAVMESH.HEIGHT_CHANGE_FACTOR; 
		return this;
	}
stayInLevel ( ) { this . currentPosition . copy ( this . position ) ; this . currentRegion = this . world . navMesh . clampMovement ( this . currentRegion , this . previousPosition , this . currentPosition , this . position ) ; this . previousPosition . copy ( this . position ) ; const distance = this . currentRegion . plane . distanceToPoint ( this . position ) ; this . position . y -= distance * CONFIG . NAVMESH . HEIGHT_CHANGE_FACTOR ; return this ; }
Ensures the enemy never leaves the level.
Ensures the enemy never leaves the level .
// "currentPosition" represents the final position after the movement for a single // simualation step. it's now necessary to check if this point is still on // the navMesh // this is the result vector that gets clamped // save this position for the next method invocation // adjust height of the entity according to the ground // smooth transition