void UTankAimingComponent::BarrelMoveTowards(FVector AimDirection)
{
//Work-Out difference between current barrel rotation, and AimDirection
auto BarrelRotator = Barrel->GetForwardVector().Rotation();
UE_LOG(LogTemp, Warning, TEXT("BarrelRotator: %s"), *BarrelRotator.ToString());
auto AimRotator = AimDirection.Rotation();
UE_LOG(LogTemp, Warning, TEXT("AimRotator: %s"), *AimRotator.ToString());
auto DeltaRotator = AimRotator - BarrelRotator;
UE_LOG(LogTemp, Warning, TEXT("DeltaRotator: %s"), *DeltaRotator.ToString());
UE_LOG(LogTemp, Warning, TEXT("DeltaRotator.Pitch: %f"), DeltaRotator.Pitch);
Barrel->Elevate(DeltaRotator.Pitch);
}
auto MC_RelativeSpeed = FMath::Clamp<float>(RelativeSpeed, -1.f, 1.f);
UE_LOG(LogTemp, Warning, TEXT("MC_RelativeSpeed: %f: "), MC_RelativeSpeed);
auto ElevateionChange = MC_RelativeSpeed * MaxDegreesPerSecond * GetWorld()->DeltaTimeSeconds;
UE_LOG(LogTemp, Warning, TEXT("ElevationChange: %f"), ElevateionChange);
UE_LOG(LogTemp, Warning, TEXT("GetRelativeRotation().Pitch: %f"), GetRelativeRotation().Pitch);
auto RawNewElevation = GetRelativeRotation().Pitch + ElevateionChange;
UE_LOG(LogTemp, Warning, TEXT("RawNewElevation: %f"), RawNewElevation);
auto MC_Elevation = FMath::Clamp(RawNewElevation, MinElevationDegrees, MaxElevationDegrees);
UE_LOG(LogTemp, Warning, TEXT("AFTER CLAMP RawNewElevation: %f"), MC_Elevation);
SetRelativeRotation(FRotator(MC_Elevation, 0.f, 0.f));
UE_LOG(LogTemp, Warning, TEXT("GetRelativeRotation().Pitch: %f"), GetRelativeRotation().Pitch);
When I change GetRelativeRotation to GetComponenRotation (inside TankBarrel)I got a weird result.
First, when I Log the values, it shows me the first Log BarrelRotator
Barrel->GetForwardVector()/GetComponentLocation.Rotation();
(inside TankAimingComponent)it is different from GetRelativeRotation().Pitch (inside TankBarrel).
BUT, when I changed GetRelativeLocation to GetComponentLocation(inside TankBarrel)
that was the result
LogTemp: Warning: AFTER CLAMP RawNewElevation: 0.000000
And notice BarrelRotator.Pitch( inside TankAimingCompoent ) it’s closer to GetCompoentLocation.Pitch ( inside TankBarrel )
- Can you explain How that happened?
- Can you tell me what is deff between RelativeLocation and ComponentLocation?
- GetForwardLocation returns just X-axis, doesn’t it?
if that is true why Y-axis and Z-axis are not 0?
please if you have answers, number them.
Thanks in advance