update method

  1. @override
MovingEntity update(
  1. double delta
)
override

Updates the internal state of this game entity.

Implementation

@override
MovingEntity update(double delta ) {
	// make sure vehicle does not exceed maximum speed
	if ( getSpeedSquared() > ( maxSpeed * maxSpeed ) ) {
		velocity.normalize();
		velocity.multiplyScalar( maxSpeed );
	}

	// calculate displacement
	displacement.copy( velocity ).multiplyScalar( delta );

	// calculate target position
	target.copy( position ).add( displacement );

	// update the orientation if the vehicle has a non zero velocity
	if ( updateOrientation && getSpeedSquared() > 0.00000001 ) {
		lookAt( target );
	}

	// update position
	position.copy( target );

	return this;
}