hi! How can i use AddControllerYawInput on actor without player, but with player controller? AddMovementInput works.
I have already tried everything (
// Fill out your copyright notice in the Description page of Project Settings.
#include "MyProject200.h"
#include "MyPlayerControllerCameraTrain.h"
#include "MyPlayerControllerCameraArm.h"
#include "MyPlayerController.h"
#include "MyPawnCameraTrain.h"
#include "MyPawnCameraArm.h"
#include "MyPawnCamera.h"
//#include "Character.h"
AMyPlayerController::AMyPlayerController() {
bShowMouseCursor = true;
bEnableClickEvents = true;
bEnableTouchEvents = false;
bEnableMouseOverEvents = true;
bEnableTouchOverEvents = false;
bAutoManageActiveCameraTarget = false;
}
void AMyPlayerController::BeginPlay() {
Super::BeginPlay();
MyPawnCamera = GetPawn();
FVector Location = FVector(0.0f, 0.0f, 0.0f);
FRotator Rotation = FRotator(0.0f, 0.0f, 0.0f);
FActorSpawnParameters SpawnParameters;
MyPawnCameraTrain = Cast<APawn>(GetWorld()->SpawnActor<AMyPawnCameraTrain>(Location, Rotation, SpawnParameters));
MyPawnCameraArm = Cast<APawn>(GetWorld()->SpawnActor<AMyPawnCameraArm>(Location, Rotation, SpawnParameters));
testcharacter = Cast<APawn>(GetWorld()->SpawnActor<ACharacter>(Location, Rotation, SpawnParameters));
//MyPawnCameraArm->AttachToActor(MyPawnCameraTrain, FAttachmentTransformRules::KeepWorldTransform);
//MyPawnCamera->AttachToActor(MyPawnCameraArm, FAttachmentTransformRules::KeepWorldTransform);
Rotation = FRotator(-70.0f, 0.0f, 0.0f);
Location = FVector(-500.0f, 0.0f, 500.0f);
MyPawnCamera->SetActorLocation(Location);
MyPawnCameraArm->SetActorRotation(Rotation);
}
void AMyPlayerController::PlayerTick(float DeltaTime) {
Super::PlayerTick(DeltaTime);
}
void AMyPlayerController::axis_forward(float value) {
if (value == 0)
return;
if (!MyPawnCameraTrain)
return;
MyPawnCameraTrain->AddMovementInput(MyPawnCameraTrain->GetActorForwardVector(), value);
UE_LOG(LogTemp, Warning, TEXT("axis_forward"));
}
void AMyPlayerController::axis_right(float value) {
if (value == 0)
return;
if (!MyPawnCameraTrain)
return;
MyPawnCameraTrain->AddMovementInput(MyPawnCameraTrain->GetActorRightVector(), value);
UE_LOG(LogTemp, Warning, TEXT("axis_right"));
}
void AMyPlayerController::axis_turn(float value) {
if (value == 0)
return;
if (!MyPawnCameraTrain)
return;
MyPawnCameraTrain->AddControllerYawInput(value);
UE_LOG(LogTemp, Warning, TEXT("axis_turn"));
}
void AMyPlayerController::axis_zoom(float value) {
if (value == 0)
return;
if (!MyPawnCamera)
return;
MyPawnCamera->AddMovementInput(MyPawnCamera->GetActorForwardVector(), value);
UE_LOG(LogTemp, Warning, TEXT("axis_zoom"));
}
void AMyPlayerController::action_mouselookPressed() {
tempAction_mouselookPressed = true;
UE_LOG(LogTemp, Warning, TEXT("action_mouselookPressed"));
}
void AMyPlayerController::action_mouselookReleased() {
tempAction_mouselookPressed = false;
UE_LOG(LogTemp, Warning, TEXT("action_mouselookReleased"));
}
void AMyPlayerController::axis_mouselookup(float value) {
if ((value == 0) ||
(!tempAction_mouselookPressed))
return;
if (!MyPawnCameraArm)
return;
MyPawnCameraArm->AddControllerPitchInput(value);
UE_LOG(LogTemp, Warning, TEXT("axis_mouselookup"));
}
void AMyPlayerController::axis_mouselookturn(float value) {
if ((value == 0) ||
(!tempAction_mouselookPressed))
return;
if (!MyPawnCameraTrain)
return;
//MyPawnCameraTrain->AddControllerYawInput(value);
//testcharacter->AddControllerYawInput(value);
Cast<AMyPlayerControllerCameraTrain>(MyPawnCameraTrain->GetController())->turn(value);
UE_LOG(LogTemp, Warning, TEXT("axis_mouselookturn"));
}
void AMyPlayerController::SetupInputComponent() {
Super::SetupInputComponent();
InputComponent->BindAxis("axis_forward", this, &AMyPlayerController::axis_forward);
InputComponent->BindAxis("axis_right", this, &AMyPlayerController::axis_right);
InputComponent->BindAxis("axis_turn", this, &AMyPlayerController::axis_turn);
InputComponent->BindAxis("axis_zoom", this, &AMyPlayerController::axis_zoom);
InputComponent->BindAction("action_mouselook", IE_Pressed, this, &AMyPlayerController::action_mouselookPressed);
InputComponent->BindAction("action_mouselook", IE_Released, this, &AMyPlayerController::action_mouselookReleased);
InputComponent->BindAxis("axis_mouselookup", this, &AMyPlayerController::axis_mouselookup);
InputComponent->BindAxis("axis_mouselookturn", this, &AMyPlayerController::axis_mouselookturn);
}
// Fill out your copyright notice in the Description page of Project Settings.
#include "MyProject200.h"
#include "MyPlayerControllerCameraTrain.h"
AMyPlayerControllerCameraTrain::AMyPlayerControllerCameraTrain() {
bShowMouseCursor = true;
bEnableClickEvents = true;
bEnableTouchEvents = false;
bEnableMouseOverEvents = true;
bEnableTouchOverEvents = false;
bAutoManageActiveCameraTarget = false;
}
void AMyPlayerControllerCameraTrain::turn(float value) {
APawn* temp = GetPawn();
temp->AddControllerYawInput(value);
UE_LOG(LogTemp, Warning, TEXT("AMyPlayerControllerCameraTrain - %s"), *temp->GetName());
}
void AMyPlayerControllerCameraTrain::BeginPlay() {
Super::BeginPlay();
}
void AMyPlayerControllerCameraTrain::PlayerTick(float DeltaTime) {
Super::PlayerTick(DeltaTime);
}
void AMyPlayerControllerCameraTrain::SetupInputComponent() {
Super::SetupInputComponent();
}
// Fill out your copyright notice in the Description page of Project Settings.
#include "MyProject200.h"
#include "MyPawnCameraTrain.h"
#include "MyPlayerControllerCameraTrain.h"
AMyPawnCameraTrain::AMyPawnCameraTrain() {
PrimaryActorTick.bCanEverTick = false;
AutoPossessAI = EAutoPossessAI::PlacedInWorldOrSpawned;
AIControllerClass = AMyPlayerControllerCameraTrain::StaticClass();
bUseControllerRotationYaw = true;
SceneComponent = CreateDefaultSubobject<USceneComponent>(TEXT("SceneComponent"));
RootComponent = SceneComponent;
FloatingPawnMovement = CreateDefaultSubobject<UFloatingPawnMovement>(TEXT("FloatingPawnMovement"));
}
void AMyPawnCameraTrain::BeginPlay() {
Super::BeginPlay();
}
//void AMyPawnCameraTrain::Tick(float DeltaTime) {
//
// Super::Tick(DeltaTime);
//}
void AMyPawnCameraTrain::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent) {
Super::SetupPlayerInputComponent(PlayerInputComponent);
}
// Fill out your copyright notice in the Description page of Project Settings.
#include "MyProject200.h"
#include "MyGameModeBase.h"
#include "MyPlayerController.h"
#include "MyPawnCamera.h"
//#include "MyPawnCameraTrain.h"
AMyGameModeBase::AMyGameModeBase() {
PlayerControllerClass = AMyPlayerController::StaticClass();
DefaultPawnClass = AMyPawnCamera::StaticClass();
}