Hello,
I’m making a RTS game, and now I make move pawns to clicked point, but when I press left mouse, in console I have information: “movement not allowed” and my pawns dont move.
Currently in game mode, my default pawn is only camera, but if I set this moveable pawn, everything work.
My character CPP class:
#include "BaseCharacter.h"
#include "Blueprint/AIBlueprintHelperLibrary.h"
#include "GameFramework/CharacterMovementComponent.h"
ABaseCharacter::ABaseCharacter()
{
PrimaryActorTick.bCanEverTick = true;
}
void ABaseCharacter::BeginPlay()
{
Super::BeginPlay();
ConfigureCharacterMovement();
}
void ABaseCharacter::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
void ABaseCharacter::ConfigureCharacterMovement()
{
UCharacterMovementComponent* CharacterMovementComponent = GetCharacterMovement();
CharacterMovementComponent->bOrientRotationToMovement = true;
CharacterMovementComponent->RotationRate = FRotator(0.f, 640.f, 0.f);
CharacterMovementComponent->bConstrainToPlane = true;
CharacterMovementComponent->bSnapToPlaneAtStart = true;
}
void ABaseCharacter::MoveToClickedPoint(FVector Location, APlayerController* PlayerController)
{
if (PlayerController == nullptr) return;
UE_LOG(LogTemp, Display, TEXT("Click location: %s"), *Location.ToString());
UAIBlueprintHelperLibrary::SimpleMoveToLocation(PlayerController, Location);
}
PlayerController CPP:
#include "BaseCharacter.h"
#include "Kismet/GameplayStatics.h"
MyPlayerController::MyPlayerController()
{
bShowMouseCursor = true;
DefaultMouseCursor = EMouseCursor::Default;
}
void MyPlayerController::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
void MyPlayerController::SetupInputComponent()
{
Super::SetupInputComponent();
InputComponent->BindAction(TEXT("Move"), IE_Pressed, this, &MyPlayerController::SendPawnsToClickedPoint);
}
void MyPlayerController::SendPawnsToClickedPoint()
{
FHitResult HitResult;
bool bIsHit = GetHitResultUnderCursor(ECC_Visibility, false, HitResult);
if (!bIsHit) return;
TArray<AActor*> BaseCharacters;
UClass* BaseCharacterClass = ABaseCharacter::StaticClass();
UGameplayStatics::GetAllActorsOfClass(GetWorld(), BaseCharacterClass, BaseCharacters);
for (AActor* baseCharacter : BaseCharacters)
{
ABaseCharacter* tmpBaseCharacter = Cast<ABaseCharacter>(baseCharacter);
if (tmpBaseCharacter == nullptr) continue;
tmpBaseCharacter->MoveToClickedPoint(HitResult.Location, this);
}
}