Quick Square root question

I want to find the Square root of something, but which header file would I need to include for Sqrt() to work please?

Like this:


float RightStickThreshold = Sqrt((aTurn * 2) + (aLookup * 2));

Thanks

It is in Fmath::Sqrt


static FORCEINLINE float Sqrt( float Value ) { return sqrtf(Value);

Btw it is not in the docs for some reason. Does anyone know why?

Thanks maikklein but its not working how I’d like. I basically want to see if a player has pushed far enough away from the centre of the right joystick. Say about half way.




void ATutorialCodeCharacter::TurnAtRate(float Value)
{

	aTurn = Value;

}

void ATutorialCodeCharacter::LookUpAtRate(float Value)
{

	aLookup = Value;
}

void ATutorialCodeCharacter::Tick(float DeltaTime)
{
float MaxThresholdForRotating = 150;

	float RightStickThreshold = FMath::Sqrt((aTurn * 2) + (aLookup * 2));


	if (RightStickThreshold >= MaxThresholdForRotating)
	{
		bRotating = true;
}
	}

When I debug RightStickThreshold I get a strange value. In some areas on the joystick I get a value of -1.#1ND00

Any suggestions please?

Thanks

Most likely scenarios is that you’re getting an [FONT=Courier New]NaN. This happens if you try to get the square root of a negative number, or of zero, both of which are valid inputs for axes. Make threshold use the absolute values of [FONT=Courier New]aTurn and [FONT=Courier New]aLookup, and if [FONT=Courier New]aTurn and [FONT=Courier New]aLookup are both 0.0, then just set threshold to 0.0 instead of attempting the calculation.

Thanks that fixed it :slight_smile: