Hi everyone,
When I want to move my character on curved ledge while hanging, my character’s rotation and movement are not synch and causing like this:
Here is my code:
// LeftArrow Relative Location: FVector(40.f, -100.f, 40.f)
Start = LeftArrow->GetComponentLocation();
End = Start + (LeftArrow->GetForwardVector() * 150);
DRAWLINE(Start, End);
FCollisionQueryParams CollisionParams;
CollisionParams.AddIgnoredActor(this);
if (GetWorld()->LineTraceSingleByChannel(OutHit, Start, End, ECC_Visibility, CollisionParams))
{
FVector DistanceToWall = (OutHit.Normal * DistToWallCoeff) + OutHit.Location;
FVector TargetLocation = FVector(DistanceToWall.X, DistanceToWall.Y, 0.f);
// pelvis is nearly in the middle of capsule so we should
// extract CapsuleHalfHeight from Z value of location
TargetLocation.Z = HeightLocation.Z - GetCapsuleComponent()->GetScaledCapsuleHalfHeight();
FRotator TargetRotator = UKismetMathLibrary::MakeRotFromX(OutHit.Normal * -1);
TargetRotator.Pitch = 0.f;
LOGM("GO: %f", FVector::Dist(GetActorLocation(), ClimbableActor->GetActorLocation()));
SetActorLocation(FMath::VInterpTo(GetActorLocation(), TargetLocation, GetWorld()->GetDeltaSeconds(), 1.0f));
SetActorRotation(FMath::RInterpTo(GetActorRotation(), TargetRotator, GetWorld()->GetDeltaSeconds(), 1.0f) );
}