rotateTo method

bool rotateTo(
  1. Vector3 target,
  2. double delta, [
  3. double? tolerance
])

Given a target position, this method rotates the entity by an amount not greater than {@link GameEntity#maxTurnRate} until it directly faces the target.

Implementation

bool rotateTo(Vector3 target, double delta, [double? tolerance] ) {
    tolerance ??= MathUtils.epsilon;
	final parent = this.parent;

	if ( parent != null ) {
		getWorldPosition( positionWorld );
		targetDirection.subVectors( target, positionWorld ).normalize();
		targetRotation.lookAt( forward, targetDirection, up );
		quaternionWorld.extractRotationFromMatrix( parent.worldMatrix() ).inverse();
		targetRotation.premultiply( quaternionWorld );
	}
    else {
		targetDirection.subVectors( target, position ).normalize();
		targetRotation.lookAt( forward, targetDirection, up );
	}

	return rotation.rotateTo( targetRotation, maxTurnRate * delta, tolerance );
}