Wall Climbing+Align to wall not working

hi . i have a character trying to stick to any surface.


 

  1. void APlayerBase::OnHit(UPrimitiveComponent* HitComponent, AActor* OtherActor, UPrimitiveComponent* OtherComponent, FVector NormalImpulse, const FHitResult& Hit)
  1. {
  1. WallCheck(Hit);
  1. }
  1. void APlayerBase::SetClimbingMode(  FHitResult _hitSurface)
  1. {
  1. floorHit = _hitSurface;
  1. ChangeCatState(ECatState::CLIMBING);
  1. GetCharacterMovement()->SetMovementMode(MOVE_Flying);
  1. GetCharacterMovement()->StopMovementImmediately();
  1. climbForwardValue= FVector::DotProduct(FVector::ForwardVector, (floorHit.ImpactNormal*-1));
  1. FVector under = _hitSurface.ImpactPoint;
  1. FVector newUp = _hitSurface.ImpactNormal;
  1. //Some math to get the new Axis
  1. FVector currentRightVect = GetActorRightVector();
  1. FVector newForward = FVector::CrossProduct(currentRightVect, newUp);
  1. FVector newRight = FVector::CrossProduct(newUp, newForward);
  1. FTransform newTransform(newForward, newRight, newUp, under);
  1. SetActorTransform(newTransform);
  1. }
  1. void APlayerBase::ClimbingMovement(float _axisScaleValue)
  1. {
  1. if (catState != ECatState::CLIMBING)return;
  1. if (_axisScaleValue < 0)
  1. {
  1. OnClimbOff();
  1. return;
  1. }
  1. float climbAxis = _axisScaleValue * climbForwardValue;
  1. GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, FString::Printf(TEXT(" %f = %f * %f;  "), climbAxis, _axisScaleValue, climbForwardValue));
  1. AddMovementInput(FVector::UpVector, climbAxis, true);
  1. //////////////////////////////////////////////////////////////////////////
  1. //check if still climbing
  1. FCollisionObjectQueryParams objectQueryParams;
  1. FCollisionQueryParams collisionQueryParams;
  1. objectQueryParams.AddObjectTypesToQuery(ECC_WorldDynamic);
  1. objectQueryParams.AddObjectTypesToQuery(ECC_WorldStatic);
  1. collisionQueryParams.AddIgnoredActor(this);
  1. // Create a damage event
  1. TSubclassOf<UDamageType> const ValidDamageTypeClass = TSubclassOf<UDamageType>(UDamageType::StaticClass());
  1. FDamageEvent DamageEvent(ValidDamageTypeClass);
  1. FHitResult hits;
  1. if (GetWorld()->LineTraceSingleByObjectType(hits, GetActorLocation(), downArrow->GetForwardVector()*100.0f, objectQueryParams, collisionQueryParams))
  1. {
  1. if (hits.Actor != NULL && hits.Component->ComponentHasTag("Climb"))
  1. {
  1. ///add for to the wall
  1. GetCharacterMovement()->AddForce(downArrow->GetForwardVector()*10000.0f);
  1. return;
  1. }
  1. }
  1. OnClimbOff(false);
  1. }

   

the problem is this.
When i test on the right wall this works fine. but when the wall is at the left the character gets crazy rotations and spins. I believe the problem is line 20


 

  1. FVector under = _hitSurface.ImpactPoint;
  1. FVector newUp = _hitSurface.ImpactNormal;
  1. //Some math to get the new Axis
  1. FVector currentRightVect = GetActorRightVector();
  1. FVector newForward = FVector::CrossProduct(currentRightVect, newUp);
  1. FVector newRight = FVector::CrossProduct(newUp, newForward);
  1. FTransform newTransform(newForward, newRight, newUp, under);
  1. SetActorTransform(newTransform);

 

Because i think that the code asumes that character is facing Y direction, but mine is facing X as forward.

Incorrect

the solution was to set


GetCharacterMovement()->bIgnoreBaseRotation = true; GetCharacterMovement()->bUseControllerDesiredRotation = false;