Hi!
I am facing problems with Moving and rotating actor, I created a simple waypoint system (without using NavMesh) and I used the following:
CDistance = FVector::Dist(Waypoints[WP]->GetActorLocation(), GetActorLocation());
if (CDistance <= 150.f) //CDistance is distance to waypoint calculated in Tick()
{
WP++;
if (WP == Waypoints.Num())
WP = 0;
CalculateNextDirection(CurrDirection);
}
else
{
UE_LOG(LogTemp, Warning, TEXT("Should Move"));
AddActorLocalOffset(GetActorForwardVector());
}
//Calculate Next Direction Method
CalculateNextDirection(FVector& CurrDirection)
{
UE_LOG(LogTemp, Warning, TEXT("Calculating next waypoint"));
CurrDirection = Waypoints[WP]->GetActorLocation() - GetActorLocation();
CurrDirection.Normalize();
FRotator NewRotation = FRotationMatrix::MakeFromX(CurrDirection).Rotator();
NewRotation.Pitch = 0.f;
NewRotation.Roll = 0.f;
SetActorRotation(NewRotation);
}
It works but after reaching the waypoint when Actor Rotates towards another waypoint, its movement direction changes (It starts to move in some random direction). What could be the problem?