When Multiply GetWorld().GetDeltaSeconds() to AddControllerYaw/PitchRotation The Camera Moves unusually

Hey, I was making a Touch Logic in which when you swipe the screen The camera moves,When I added The Yaw and Pitch Rotation it worked great But the sensitivity was very high so I first Multiplied the Yaw and Pitch Values by WorldDeltaSeconds but The Camera Moved Unusually so instead of delta seconds I divided the value by 5 but still the The Camera moved unusually, when I printed the log of the value divided by 5 I got to see that the divided value is bigger than the non divided one, this was same too with the Delta Seconds, I wrote the same code in blueprints and executed it, it worked fine, but in C++ I got errors,
This is The Video of The Error-
Video file here
Please, can anyone help me to figure out this error?
This is My Code-

//.h file-
bool IsTouchMoved();
	bool TouchP;
	bool TouchMoved;
	FVector2D CurrTouchMoved;
	FVector2D PrevTouchMoved;
	float X;
	float Y;
	float PrevX;
	float PrevY;
	bool DidOnce;
	bool IsTouched;

//In Tick-
FVector2D TouchLocation;
	APlayerController* ActivePlayerController = UGameplayStatics::GetPlayerController(this, 0);
	ActivePlayerController->GetInputTouchState(ETouchIndex::Touch1, TouchLocation.X, TouchLocation.Y, IsTouched);
	if (!IsTouched)
	{
		DidOnce = false;
	}
	if (IsTouchMoved())
	{
		if (!DidOnce)
		{
			ActivePlayerController->GetInputTouchState(ETouchIndex::Touch1, PrevX, PrevY, IsTouched);
			DidOnce = true;
		}
		ActivePlayerController->GetInputTouchState(ETouchIndex::Touch1, X, Y, IsTouched);
		AddControllerYawInput(X - PrevX / 5);
		AddControllerPitchInput(Y - PrevY / 5);
		ActivePlayerController->GetInputTouchState(ETouchIndex::Touch1, PrevX, PrevY, IsTouched);
}

//In Begin Play-
DidOnce = false;

//In bool IsTouchMoved()-
{
	APlayerController* ActivePlayerController = UGameplayStatics::GetPlayerController(this, 0);
	ActivePlayerController->GetInputTouchState(ETouchIndex::Touch1, CurrTouchMoved.X, CurrTouchMoved.Y, TouchP);
	CurrTouchMoved.X = (int32)CurrTouchMoved.X;
	CurrTouchMoved.Y = (int32)CurrTouchMoved.Y;
	if (CurrTouchMoved != PrevTouchMoved)
	{
		TouchMoved = true;
	}
	else if (CurrTouchMoved == PrevTouchMoved)
	{
		TouchMoved = false;
	}
	ActivePlayerController->GetInputTouchState(ETouchIndex::Touch1, PrevTouchMoved.X, PrevTouchMoved.Y, TouchP);
	PrevTouchMoved.X = (int32)PrevTouchMoved.X;
	PrevTouchMoved.Y = (int32)PrevTouchMoved.Y;
	return TouchMoved;
}

Multiplication and division take priority over additions/substraction. Use parenthesis :

(X - PrevX) / 5

Read up on c++ operator precedence.

2 Likes

Thanks😊