AddControllerYawInput without player

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();
}

i can move(addmovementinput) multiply pawns with 1 main player controller and many aicontrollers, but cant rotate(AddControllerYawInput). how can i do it?

i think i need to replace all aicontroller with playercontrollers, becouse aicontroller cant rotate(i cant change his pawn rotation in runtime editor). but what next? i can rotate only pawn with main player controller, but why cant other?

Hi,
just test the following. Make a blueprint from your c++ class and check if the flag Use Control Rotation is set. If not, then the pawn or char will not rotate even if the controller rotates.
Hope that helps.
Cheers

pawn starts rotating when i possess main player controller in. dont know what next :frowning: here some changes:
GameMode:


#include "MyProject200.h"
#include "MyGameModeBase.h"
#include "MyPlayerController.h"
#include "MyPawnCamera.h"

AMyGameModeBase::AMyGameModeBase() {

	PlayerControllerClass = AMyPlayerController::StaticClass();
	DefaultPawnClass = AMyPawnCamera::StaticClass();
}

Main PlayerController:


#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;
}

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));

	MyPawnCameraArm->AttachToActor(MyPawnCameraTrain, FAttachmentTransformRules::KeepWorldTransform);
	MyPawnCamera->AttachToActor(MyPawnCameraArm, FAttachmentTransformRules::KeepWorldTransform);

	Rotation = FRotator(-75.0f, 0.0f, 0.0f);
	Location = FVector(-600.0f, 0.0f, 0.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);
	UE_LOG(LogTemp, Warning, TEXT("axis_mouselookturn"));
}

void AMyPlayerController::test1() {

	Possess(MyPawnCamera);
	UE_LOG(LogTemp, Warning, TEXT("test1"));
}

void AMyPlayerController::test2() {

	Possess(MyPawnCameraArm);
	UE_LOG(LogTemp, Warning, TEXT("test2"));
}

void AMyPlayerController::test3() {

	Possess(MyPawnCameraTrain);
	UE_LOG(LogTemp, Warning, TEXT("test3"));
}

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);

	InputComponent->BindAction("test1", IE_Released, this, &AMyPlayerController::test1);
	InputComponent->BindAction("test2", IE_Released, this, &AMyPlayerController::test2);
	InputComponent->BindAction("test3", IE_Released, this, &AMyPlayerController::test3);
}

Camera Pawn:


#include "MyProject200.h"
#include "MyPawnCamera.h"
//#include "MyPlayerController.h"

AMyPawnCamera::AMyPawnCamera() {

	PrimaryActorTick.bCanEverTick = false;
	//AutoPossessAI = EAutoPossessAI::PlacedInWorldOrSpawned;
	//AIControllerClass = MyPlayerControllerCameraArm::StaticClass();

	SceneComponent = CreateDefaultSubobject<USceneComponent>(TEXT("SceneComponent"));
	RootComponent = SceneComponent;

	CameraComponent = CreateDefaultSubobject<UCameraComponent>(TEXT("CameraComponent"));
	CameraComponent->SetupAttachment(SceneComponent);

	FloatingPawnMovement = CreateDefaultSubobject<UFloatingPawnMovement>(TEXT("FloatingPawnMovement"));
}

void AMyPawnCamera::BeginPlay() {

	Super::BeginPlay();
}

//void AMyPawnCamera::Tick(float DeltaTime) {
//
//	Super::Tick(DeltaTime);
//}

void AMyPawnCamera::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent) {

	Super::SetupPlayerInputComponent(PlayerInputComponent);
}

CameraArm Pawn:


#include "MyProject200.h"
#include "MyPawnCameraArm.h"
#include "MyPlayerControllerCameraArm.h"


AMyPawnCameraArm::AMyPawnCameraArm() {

	PrimaryActorTick.bCanEverTick = false;
	AutoPossessAI = EAutoPossessAI::PlacedInWorldOrSpawned;
	AIControllerClass = AMyPlayerControllerCameraArm::StaticClass();
	bUseControllerRotationPitch = true;

	SceneComponent = CreateDefaultSubobject<USceneComponent>(TEXT("SceneComponent"));
	RootComponent = SceneComponent;

	FloatingPawnMovement = CreateDefaultSubobject<UFloatingPawnMovement>(TEXT("FloatingPawnMovement"));
}

void AMyPawnCameraArm::BeginPlay() {

	Super::BeginPlay();
}

//void AMyPawnCameraArm::Tick(float DeltaTime) {
//
//	Super::Tick(DeltaTime);
//}

void AMyPawnCameraArm::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent) {
	
	Super::SetupPlayerInputComponent(PlayerInputComponent);
}

CameraTrain Pawn:


#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);
}

Here is other controllers:


#include "MyProject200.h"
#include "MyPlayerControllerCameraArm.h"

AMyPlayerControllerCameraArm::AMyPlayerControllerCameraArm() {

	bShowMouseCursor = true;
	bEnableClickEvents = true;
	bEnableTouchEvents = false;
	bEnableMouseOverEvents = true;
	bEnableTouchOverEvents = false;
}

void AMyPlayerControllerCameraArm::BeginPlay() {

	Super::BeginPlay();
}

void AMyPlayerControllerCameraArm::PlayerTick(float DeltaTime) {

	Super::PlayerTick(DeltaTime);
}

void AMyPlayerControllerCameraArm::SetupInputComponent() {

	Super::SetupInputComponent();
}


#include "MyProject200.h"
#include "MyPlayerControllerCameraTrain.h"

AMyPlayerControllerCameraTrain::AMyPlayerControllerCameraTrain() {

	bShowMouseCursor = true;
	bEnableClickEvents = true;
	bEnableTouchEvents = false;
	bEnableMouseOverEvents = true;
	bEnableTouchOverEvents = false;
}

void AMyPlayerControllerCameraTrain::BeginPlay() {

	Super::BeginPlay();
}

void AMyPlayerControllerCameraTrain::PlayerTick(float DeltaTime) {

	Super::PlayerTick(DeltaTime);
}

void AMyPlayerControllerCameraTrain::SetupInputComponent() {

	Super::SetupInputComponent();
}

When i press test1, test2, test3 i can possess in pawn and rotate it individually, but cant rotate all together :frowning:

I learned to use debugging :slight_smile:


/* PlayerTick is only called if the PlayerController has a PlayerInput object.  Therefore, it will not be called on servers for non-locally controlled playercontrollers. */
void APlayerController::PlayerTick( float DeltaTime )
{
	if (!bShortConnectTimeOut)
	{
		bShortConnectTimeOut = true;
		ServerShortTimeout();
	}

	TickPlayerInput(DeltaTime, DeltaTime == 0.f);

	if ((Player != NULL) && (Player->PlayerController == this))
	{
		// Validate current state
		bool bUpdateRotation = false;
		if (IsInState(NAME_Playing))
		{
			if( GetPawn() == NULL )
			{
				ChangeState(NAME_Inactive);
			}
			else if (Player && GetPawn() && GetPawn() == AcknowledgedPawn)
			{
				bUpdateRotation = true;
			}
		}
		
		if ( IsInState(NAME_Inactive) )
		{
			if (Role < ROLE_Authority)
			{
				SafeServerCheckClientPossession();
			}

			bUpdateRotation = !IsFrozen();
		}
		else if ( IsInState(NAME_Spectating) )
		{
			if (Role < ROLE_Authority)
			{
				SafeServerUpdateSpectatorState();
			}

			bUpdateRotation = true;
		}

		// Update rotation
		if (bUpdateRotation)
		{
			UpdateRotation(DeltaTime);
		}
	}
}

i need rotate pawn with player controller, but when player = null :frowning:
what should I do?

put


	if (Player == NULL)
		UpdateRotation(DeltaTime);

in player controller tick event :slight_smile:

What is the best way to move to a location using AddMovementInput?
I do not want to use the SetActorLocation and the VInterp, because I have a UFloatingPawnMovement component for this. Or is there another way how to use it for smooth moving to location?

Same question for AddControllerYawInput and AddControllerPitchInput. Thanks.

P.S. i can not use navigation, because it is Camera(it is necessary to move through objects).