[HELP NEEDED] Can't get MoveVelocity.GetSafeNormal() working

Hey,
I’m trying to normalize the MoveVelocity just as in the video, but logging the vector to the console shows that it hasn’t been normalized at all. I tried it with and without providing a float parameter in GetSafeNormal() and I also tried GetUnsafeNormal(). Using UE 4.23.0.

It’s really confusing me because it seems such a simple thing… Any help much appreciated!

Screenshot of the map (player selected) and console output:

TankNavMovementComponent.cpp:

    #include "TankNavMovementComponent.h"
    #include "TankTrack.h"
     
    #pragma region Overrides
     
    void UTankNavMovementComponent::RequestDirectMove(const FVector& MoveVelocity, bool bForceMaxSpeed)
    {
    	// No need to call Super. Logic will be replaced.
     
    	const FVector TankForwardVectorNormal = GetOwner()->GetActorForwardVector();
    	// BUG: Why doesn't this get normalized?
    	const auto MoveVelocityNormal = MoveVelocity.GetSafeNormal(0.0001f);
    	const float ForwardThrow = FVector::DotProduct(TankForwardVectorNormal, MoveVelocityNormal);
     
    	UE_LOG(LogTemp, Warning, TEXT("[%s] MoveVelocity: %s"), *GetOwner()->GetName(), *MoveVelocity.ToString());
     
    	UE_LOG(LogTemp, Warning, TEXT("[%s] TankForwardVectorNormal: %s, MoveVelocityNormal: %s, ForwardThrow: %f"),
    		*GetOwner()->GetName(),
    		*TankForwardVectorNormal.ToString(),
    		*MoveVelocityNormal.ToString(),
    		ForwardThrow);
     
    	IntendMoveForward(ForwardThrow);
    }
     
    #pragma endregion

Answered on Udemy. It’s an issue with FMath::InvSqrt doing the wrong thing with MSVC under /O2 and I’ve filled a bug report to Epic

1 Like

Thanks for reporting. Probably you were able to describe the problem in more detail than I would have been able to. Can you provide the link to the bug report so I (and others) can upvote it?

There’s no ticket for it (yet). I would assume they’re just going to forward it to the MSVC team. I would have filled it with them too but I figured the legalities of pasting their code for their implementation of that function would be a problem.

Though to illlustrate the issue, left is GCC without and with optimisations (-O0, -O3) and the same with MSVC on the right (Debug/Release)

Edit: This issue has been fixed in Visual Studio 2019 16.4. If you’re using 16.3 please update.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms