Hey, I saw many people taking marketplace assets to just make the camera rotate with touch swipe, So I thought to make a code to help you out and save your’s money, This is the code just add these code lines at the correct places in your character code, and 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 DidOnce2;
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;
DidOnce2 = false;
//In bool IsTouchMoved()-
{
APlayerController* ActivePlayerController = UGameplayStatics::GetPlayerController(this, 0);
if (!DidOnce2)
{
ActivePlayerController->GetInputTouchState(ETouchIndex::Touch1, PrevTouchMoved.X, PrevTouchMoved.Y, TouchP);
DidOnce2 = true;
}
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;
}
//I am not sure but if I will make a marketplace pack of it I will tell you all, It will be free.