Hi all,
Trying to get an actor to slowly turn towards a location, I couldn’t get the KismetMathLibrary for FindLookAtRotation working in the code* so I instead followed another answer here that suggested
void AShipAIController::Tick(float DeltaSeconds){
if (bIsDestinationSet){
AShip* ship = Cast<AShip>(this->GetPawn());
FVector currentLocation = ship->GetActorLocation();
FRotator rotation = FRotationMatrix::MakeFromX(CurrentDestination - currentLocation).Rotator();
float rotationYaw = rotation.Yaw;
float turn = TurnRate;
//If negative rotation, multiply turn speed by -1
if (rotationYaw < 0){
turn = turn * -1.0f;
}
//Turn actor
FRotator turnby = FRotator(0, turn, 0);
ship->AddActorLocalRotation(turnby);
}
}
I want to be able to stop the rotation once the object is facing the target. Mainly I was thinking if I kept calculating the rotation from FRotationMatrix until it got somewhere close to 0 I could implement some stopping logic. However, the rotation from FRotationMatrix never changes even though I can see the actor rotating in the viewport.
Any ideas why, or am I thinking about this all wrong? Does the FRotation matrix provide a angle between two points, or does it provide the amount of rotation needed to face it?
Thanks.
*The problem I had with KismetMathLibrary is that when compiling visual studio could not find “KismetMathLibrary.h”, if you know how to fix this, please do tell.