I encountered a problem that when replicating movement, the character cannot turn off rotation replication, but if you turn off movement replication, then the addMovementInput function stops working. It would be enough for me to have a working addMovementInput function so that my function of moving to a certain point would work.
How can I find a solution for this situation?
void ATopDownCharacter::MoveToPointOnWorld(const float DeltaTime,
const FVector MoveToVector,
const bool IsMoved)
{
FVector Direction = (MoveToVector - GetActorLocation());
Direction.Z = 0.0f;
Direction.Normalize();
if (!Direction.IsZero())
{
FRotator RemainingRotation;
const FRotator TargetRotation = UKismetMathLibrary::FindLookAtRotation(GetActorLocation(), MoveToVector);
const FRotator CurrentRotation = GetActorRotation();
RemainingRotation.Roll = CurrentRotation.Yaw - TargetRotation.Yaw;
RemainingRotation.Roll = FMath::ClampAngle(RemainingRotation.Roll, -ClampVar, ClampVar);
FRotator NewRotation = FMath::RInterpTo(CurrentRotation, TargetRotation, DeltaTime, RotationSpeed);
NewRotation.Roll = FMath::FInterpTo(CurrentRotation.Roll, -RemainingRotation.Roll, DeltaTime, RotationSpeed);
SetActorRotation(NewRotation);
if ((abs(RemainingRotation.Roll) < AngleDifferenceConstant) and IsMoved)
{
AddMovementInput(Direction, MoveSpeed, false);
}
}
}
Here is my movement code. My character is some kind of underwater tray. It would be really nice to keep the UE movement prediction logic and make it so that the rotation does not get stuck.