I want to Calculate the Movement Angle an NOT the Rotation from an Moving Actor (to be specific = from a Bullet). First of, I´ve got the Location of the Actor and the Location one Frame before, then calculating the distance between them with FVector::Dist... After that I got the height difference between the current and last Location. Then the A-Tangents from these two variables. I put all these Variables into a Raycast.
When I shoot the Actor forwards it looks good;
but when I shoot the Bullet up, the Raycast gets messed up:
CODE: `void ABullet::Tick(float DeltaTime) { Super::Tick(DeltaTime);
if (Counter == true)
{
FVector TraceLoc = GetActorLocation();
FRotator TraceRot = GetActorRotation() + FRotator(0.f, 90.f, 0.f);
float Distance = FVector::Dist(LastActorLoc, TraceLoc);
heightdiff = TraceLoc.Z - LastActorLoc.Z;
TraceRot.Pitch = (atan(heightdiff / Distance)) * (180.f / 3.141592f);
UE_LOG(LogTemp, Warning, TEXT("Out: %f"), TraceRot.Pitch);
FVector Start = TraceLoc;
FVector End = Start + (TraceRot.Vector() * Distance);
LastActorLoc = TraceLoc;
LastActorRot = TraceRot;
FCollisionQueryParams TraceParamsBullet;
bool bHitBullet = GetWorld()->LineTraceSingleByChannel(TraceHitResultBullet, Start, End, ECC_Visibility, TraceParamsBullet);
DrawDebugLine(GetWorld(), Start, End, FColor::Red, false, 15.f, 30.f);
}
if (Counter == false)
{
Counter = true;
LastActorLoc = GetActorLocation();
LastActorRot = GetActorRotation() + FRotator(0.f, 90.f, 0.f);
}
}`