src/core/WeaponSystem.js
/**
	* Updates the aiming and shooting of the enemy.
	*
	* @param {Number} delta - The time delta value.
	* @return {WeaponSystem} A reference to this weapon system.
	*/
Updates the aiming and shooting of the enemy.
@param {Number} delta - The time delta value.
@return {WeaponSystem} A reference to this weapon system.
Updates the aiming and shooting of the enemy . @param { Number } delta - The time delta value . @return { WeaponSystem } A reference to this weapon system .
updateAimAndShot( delta ) {
		const owner = this.owner;
		const targetSystem = owner.targetSystem;
		const target = targetSystem.getTarget();
		if ( target ) {
			if ( targetSystem.isTargetShootable() ) {
				owner.resetSearch();
				const targeted = owner.rotateTo( target.position, delta, 0.05 ); 
				const timeBecameVisible = targetSystem.getTimeBecameVisible();
				const elapsedTime = owner.world.time.getElapsed();
				if ( targeted === true && ( elapsedTime - timeBecameVisible ) >= this.reactionTime ) {
					target.bounds.getCenter( targetPosition );
					this.addNoiseToAim( targetPosition );
					this.shoot( targetPosition );
				}
			} else {
				if ( owner.searchAttacker ) {
					targetPosition.copy( owner.position ).add( owner.attackDirection );
					owner.rotateTo( targetPosition, delta );
				} else {
					owner.rotateTo( targetSystem.getLastSensedPosition(), delta );
				}
			}
		} else {
			if ( owner.searchAttacker ) {
				targetPosition.copy( owner.position ).add( owner.attackDirection );
				owner.rotateTo( targetPosition, delta );
			} else {
				displacement.copy( owner.velocity ).normalize();
				targetPosition.copy( owner.position ).add( displacement );
				owner.rotateTo( targetPosition, delta );
			}
		}
		return this;
	}
updateAimAndShot ( delta ) { const owner = this . owner ; const targetSystem = owner . targetSystem ; const target = targetSystem . getTarget ( ) ; if ( target ) { if ( targetSystem . isTargetShootable ( ) ) { owner . resetSearch ( ) ; const targeted = owner . rotateTo ( target . position , delta , 0.05 ) ; const timeBecameVisible = targetSystem . getTimeBecameVisible ( ) ; const elapsedTime = owner . world . time . getElapsed ( ) ; if ( targeted === true && ( elapsedTime - timeBecameVisible ) >= this . reactionTime ) { target . bounds . getCenter ( targetPosition ) ; this . addNoiseToAim ( targetPosition ) ; this . shoot ( targetPosition ) ; } } else { if ( owner . searchAttacker ) { targetPosition . copy ( owner . position ) . add ( owner . attackDirection ) ; owner . rotateTo ( targetPosition , delta ) ; } else { owner . rotateTo ( targetSystem . getLastSensedPosition ( ) , delta ) ; } } } else { if ( owner . searchAttacker ) { targetPosition . copy ( owner . position ) . add ( owner . attackDirection ) ; owner . rotateTo ( targetPosition , delta ) ; } else { displacement . copy ( owner . velocity ) . normalize ( ) ; targetPosition . copy ( owner . position ) . add ( displacement ) ; owner . rotateTo ( targetPosition , delta ) ; } } return this ; }
Updates the aiming and shooting of the enemy.
Updates the aiming and shooting of the enemy .
// if the target is visible, directly rotate towards it and then // fire a round // stop search for the attacker if the target is shootable // the bot can fire a round if it is headed towards its target // and after a certain reaction time // "targeted" is true if the enemy is faced to the target // the target might not be shootable but the enemy is still attacked. // in this case, search for the attacker // otherwise rotate to the latest recorded position // if the enemy has no target, look for an attacker if necessary // if the enemy has no target and is not being attacked, just look along // the movement direction