On Windows, what I’ve done works great, exactly as expected. Getting it to work on Android has been a nightmare. I finally got touch controls to actually work but now the AI behavior is acting strange.
I’m making pretty basic CRPG/RTS controls, yet for some reason my selected character is set to run towards (0,0,0) on Android at all times - something that isn’t happening on Windows at all. It’s as though it clicks (0,0,0) whenever I lift my finger and idk why that is - and this only happens on Android.
Here’s the function:
void APlayerCam::select()
{
FHitResult hitRes;
if (isTouch) {
playerController->GetHitResultUnderFinger(ETouchIndex::Touch1, ECollisionChannel::ECC_Visibility, true, hitRes);
}
else {
playerController->GetHitResultUnderCursorByChannel(UEngineTypes::ConvertToTraceType(ECC_Visibility), true, hitRes);
}
//playerController->GetHitResultUnderFingerByChannel(ETouchIndex::Touch1, UEngineTypes::ConvertToTraceType(ECC_Visibility), true, hitRes);
if (ACharParent* selected = Cast<ACharParent>(hitRes.GetActor())) {
selectedUnit = selected;
//UE_LOG(LogTemp, Warning, TEXT("New Character Selected"));
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Orange, TEXT("New Char Selected"));
}
else if (AEnemyParent* selectedEnemy = Cast<AEnemyParent>(hitRes.GetActor())) {
if (selectedUnit != nullptr)
{
selectedUnit->currentEnemy = selectedEnemy;
}
}
else {
if (selectedUnit != nullptr)
{
const FVector targetPOS = hitRes.Location;
selectedUnit->aiCont->MoveToLocation(targetPOS);
selectedUnit->moveSpeedAdj();
selectedUnit->currentEnemy = nullptr;
selectedUnit->isAttacking = false;
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Orange, FString::Printf(TEXT("%s"), *targetPOS.ToString()));
}
else {
//UE_LOG(LogTemp, Warning, TEXT("No Character Selected"));
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Orange, TEXT("No Char Selected"));
}
}
}