Advertisement
Guest User

Untitled

a guest
Apr 7th, 2020
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.10 KB | None | 0 0
  1. FVector UCustomMovementComponent::ComputeSlideVector(const FVector& Delta, const float Time, const FVector& Normal, const FHitResult& Hit) const
  2. {
  3.     // Delta Input is basically just Velocity.
  4.  
  5.     if (!bConstrainToPlane)
  6.     {
  7.         FVector impactProject = FVector::VectorPlaneProject(Normal, FVector(0.f, 0.f, 1.f)).GetSafeNormal();   
  8.         FVector wishDir = InputDirection;
  9.         FVector ForwardVector = CharacterOwner->GetActorForwardVector();
  10.         float EffectiveAngle = FMath::Abs(FVector::DotProduct(-impactProject, wishDir));
  11.  
  12.         if (CharacterOwner->GetLocalRole() == ROLE_Authority)
  13.         {
  14.             // Always Zero
  15.             GEngine->AddOnScreenDebugMessage(1, 1.f, FColor::Green, FString::Printf(TEXT("Server: %s"), *wishDir.ToString()));
  16.         }
  17.         else
  18.         {
  19.             GEngine->AddOnScreenDebugMessage(2, 1.f, FColor::Red, FString::Printf(TEXT("Client: %s"), *wishDir.ToString()));
  20.         }
  21.        
  22.         float velocityScale = Delta.Size();
  23.         FVector newAngle = FMath::Lerp(Delta, ForwardVector, EffectiveAngle).GetSafeNormal();
  24.         newAngle *= velocityScale;
  25.         FVector newReturn = FVector::VectorPlaneProject(newAngle, Normal) * Time;
  26.  
  27.         return newReturn;
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement