I had make top down view game but in order to move the character, I want to use the movement button (JoystickLeftOnly) like in the third-person. I will build this on android, but when I hit Play in the editor, the Character does not move at all. Here is the code that I used:
Character.cpp
// Fill out your copyright notice in the Description page of Project Settings.
#include "RiseOfGaruda.h"
#include "RiseOfGarudaCharacter.h"
#include "Runtime/CoreUObject/Public/UObject/ConstructorHelpers.h"
// Sets default values
ARiseOfGarudaCharacter::ARiseOfGarudaCharacter()
{
// set size player capsule
GetCapsuleComponent()->InitCapsuleSize(60.f, 100.0f);
BaseTurnRate = 45.f;
// Don't rotate character to camera direction
bUseControllerRotationPitch = false;
bUseControllerRotationYaw = true;
bUseControllerRotationRoll = true;
// Configure character movement
GetCharacterMovement()->bOrientRotationToMovement = true; // Rotate character to moving direction
GetCharacterMovement()->RotationRate = FRotator(0.f, 640.f, 0.f);
GetCharacterMovement()->bConstrainToPlane = true;
GetCharacterMovement()->bSnapToPlaneAtStart = true;
// Create a camera boom...
CameraBoom = CreateDefaultSubobject<USpringArmComponent>(TEXT("CameraBoom"));
CameraBoom->AttachTo(RootComponent);
CameraBoom->bAbsoluteRotation = true; // Don't want arm to rotate when character does
CameraBoom->TargetArmLength = 800.f;
CameraBoom->RelativeRotation = FRotator(-60.f, 0.f, 0.f);
CameraBoom->bDoCollisionTest = false; // Don't want to pull camera in when it collides with level
// Create a camera...
TopDownCameraComponent = CreateDefaultSubobject<UCameraComponent>(TEXT("TopDownCamera"));
TopDownCameraComponent->AttachTo(CameraBoom, USpringArmComponent::SocketName);
TopDownCameraComponent->bUsePawnControlRotation = false; // Camera does not rotate relative to arm
// Set this character to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
PrimaryActorTick.bStartWithTickEnabled =true;
}
// Called when the game starts or when spawned
void ARiseOfGarudaCharacter::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
//void ARiseOfGarudaCharacter::Tick( float DeltaTime )
//{
// Super::Tick( DeltaTime );
//
//}
void ARiseOfGarudaCharacter::TurnAtRate(float Rate)
{
// calculate delta for this frame from the rate information
AddControllerYawInput(Rate * BaseTurnRate * GetWorld()->GetDeltaSeconds());
}
void ARiseOfGarudaCharacter::MoveXAxis(float Value)
{
if ((Controller != NULL) && (Value != 0.0f))
{
// find out which way is forward
const FRotator Rotation = Controller->GetControlRotation();
const FRotator YawRotation(0, Rotation.Yaw, 0);
// get forward vector
const FVector Direction = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::X);
AddMovementInput(Direction, Value);
}
}
void ARiseOfGarudaCharacter::MoveYAxis(float Value)
{
if ( (Controller != NULL) && (Value != 0.0f) )
{
// find out which way is right
const FRotator Rotation = Controller->GetControlRotation();
const FRotator YawRotation(0, Rotation.Yaw, 0);
// get right vector
const FVector Direction = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::Y);
// add movement in that direction
AddMovementInput(Direction, Value);
}
}
// Called to bind functionality to input
void ARiseOfGarudaCharacter::SetupPlayerInputComponent(class UInputComponent* InputComponent)
{
Super::SetupPlayerInputComponent(InputComponent);
check(InputComponent)
InputComponent->BindAxis("MoveXAxis", this, &ARiseOfGarudaCharacter::MoveXAxis);
InputComponent->BindAxis("MoveYAxis", this, &ARiseOfGarudaCharacter::MoveYAxis);
}
Controller.cpp
// Fill out your copyright notice in the Description page of Project Settings.
#include "RiseOfGaruda.h"
#include "RiseOfGarudaController.h"
#include "AI/Navigation/NavigationSystem.h"
ARiseOfGarudaController::ARiseOfGarudaController()
{
}
void ARiseOfGarudaController::SetupInputComponent()
{
// set up gameplay key bindings
Super::SetupInputComponent();
// InputComponent->BindAction("SetDestination", IE_Pressed, this, &AMyProject3PlayerController::OnSetDestinationPressed);
// InputComponent->BindAction("SetDestination", IE_Released, this, &AMyProject3PlayerController::OnSetDestinationReleased);
// support touch devices
// InputComponent->BindAction(EInputEvent::IE_Pressed, this, ARiseOfGarudaController::MoveXAxis);
// InputComponent->BindAction(EInputEvent::IE_Pressed, this, &ARiseOfGarudaController::MoveYAxis);
}
and here is my blueprint settings [In Picture]:
**
**
at first i am thinking on adding the event, but it seems the C++ in other template does not implement the event.
What I am thinking is that it is like TPS template, but just change the camera to TopDownView, but unfortunately I mistaken.
Hope someone can help me to have better understanding…