TeamInit() is being called in the game mode’s “SpawnDefaultFor”
Moved the logic out of the server RPC, but the client player is still unable to move their character.
Also when the client player does an aimed attack, their rotation only updates on the client and not server.
Swapping between team characters, which is called from the player controller is working. Starting attacks, which is called in ABasePlayableCharacter, is also working, but the aim is wrong.
The only things that aren’t working as intended is the aiming and moving.
Here’s the logic for moving and doing an aimed attack
void ABrawlersOfDualityPlayerController::PlayerTick(float DeltaTime)
{
Super::PlayerTick(DeltaTime);
if(!IsLocalController()) return;
if(bInputPressed)
{
FollowTime += DeltaTime;
// Look for the touch location
FVector HitLocation = FVector::ZeroVector;
FHitResult Hit;
if(bIsTouch)
{
GetHitResultUnderFinger(ETouchIndex::Touch1, ECC_Visibility, true, Hit);
}
else
{
GetHitResultUnderCursor(ECC_Visibility, true, Hit);
}
HitLocation = Hit.Location;
// Direct the Pawn towards that location
if(bTeamInitialized && TeamCharacters.Num() > 0)
{
if (GEngine)
{
GEngine->AddOnScreenDebugMessage(-1, 0.016f,FColor::Red,FString(TEXT("Calling move forward")));
}
FVector WorldDirection = (HitLocation - TeamCharacters[0]->GetActorLocation()).GetSafeNormal();
TeamCharacters[0]->MoveForward((float) WorldDirection.X);
TeamCharacters[0]->MoveRight((float) WorldDirection.Y);
}
}
else
{
FollowTime = 0.f;
}
}
void ABasePlayableCharacter::MoveForward(float Value)
{
if(bDisableGameplay)
{
return;
}
else if(Controller != nullptr && Value != 0.f)
{
const FRotator YawRotation(0.f, Controller->GetControlRotation().Yaw, 0.f);
const FVector Direction(FRotationMatrix(YawRotation).GetUnitAxis(EAxis::X));
AddMovementInput(Direction, Value);
}
}
void ABasePlayableCharacter::AimForward(float Value)
{
if(bDisableGameplay)
{
return;
}
if (Controller != nullptr && Value != 0.f)
{
const FRotator YawRotation(0.f, Controller->GetControlRotation().Yaw, 0.f);
const FVector Direction(FRotationMatrix(YawRotation).GetUnitAxis(EAxis::X));
bAimForward = true;
AimForwardValue = Value;
}
else
{
bAimForward = false;
}
}
//used for gamepad controls and non aimed mouse and keyboard attacks
void ABasePlayableCharacter::LightAttackButtonReleased()
{
if(bDisableGameplay) return;
if(CombatState == ECombatState::ECS_Idle || CombatState == ECombatState::ECS_Walking)
{
bDisableGameplay = true;
if(bAimForward || bAimRight)
{
GetCharacterMovement()->bOrientRotationToMovement = false;
FVector LookAt(AimForwardValue,AimRightValue,0.f);
SetActorRotation(LookAt.Rotation());
SetCombatState(ECombatState::ECS_LightAim);
}
else
{
SetCombatState(ECombatState::ECS_LightTap);
}
}
else if(CombatState == ECombatState::ECS_Dashing)
{
SetCombatState(ECombatState::ECS_DashLightTap);
}
}
void ABasePlayableCharacter::LookAtMouse()
{
BrawlerPlayerController = BrawlerPlayerController == nullptr ? Cast(Controller) : BrawlerPlayerController;
if (BrawlerPlayerController)
{
UE_LOG(LogTemp, Warning, TEXT(“LookAtMouse”));
FHitResult HitResult;
BrawlerPlayerController->GetHitResultUnderCursor(
ECollisionChannel::ECC_Visibility,
false,
HitResult);
LookAtLocation(HitResult.ImpactPoint);
}
}
//used for mouse and keyboard controls
void ABasePlayableCharacter::LightAimAttackButtonReleased()
{
if(bDisableGameplay) return;
if(CombatState == ECombatState::ECS_Idle || CombatState == ECombatState::ECS_Walking)
{
LookAtMouse();
bDisableGameplay = true;
SetCombatState(ECombatState::ECS_LightAim);
}
}
I’m having issues understanding when the server is using information from the client copy of the controller vs the server copy of the controller