The tank does not move


when i press play my tank does not move when i press w s d a, id ont know why
here is the code
#include “Tank.h”

#include “GameFramework/SpringArmComponent.h”

#include"Camera/CameraComponent.h"

#include “Components/InputComponent.h”

#include “Kismet/GameplayStatics.h”

#include “DrawDebugHelpers.h”

ATank::ATank()

{

SpringArm = CreateDefaultSubobject(TEXT(“SpringArm”));

SpringArm → SetupAttachment(RootComponent);

Camera = CreateDefaultSubobject(TEXT(“Camera”));

Camera → SetupAttachment(SpringArm);

}

void ATank::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)

{

Super::SetupPlayerInputComponent(PlayerInputComponent);

PlayerInputComponent -> BindAxis(TEXT("MoveFoward"), this, &ATank::Move);

PlayerInputComponent -> BindAxis(TEXT("Turn"), this, &ATank::Turn);

}

void ATank::Tick(float DeltaTime)

{

Super::Tick(DeltaTime);

FHitResult HitResult;

if(PlayerControllerRef)

{

    PlayerControllerRef -> GetHitResultUnderCursor(ECollisionChannel::ECC_Visibility, false, HitResult);

           

RotateTurret(HitResult.ImpactPoint);

}

}

void ATank::BeginPlay()

{

Super::BeginPlay();

PlayerControllerRef = Cast<APlayerController>(GetController());

}

void ATank::Move(float Value)

{

FVector DeltaLocation = FVector::ZeroVector;

DeltaLocation.X = Value * Speed * UGameplayStatics::GetWorldDeltaSeconds(this);

AddActorLocalOffset(DeltaLocation, true);

}

void ATank::Turn(float Value)

{

FRotator DeltaRotation = FRotator::ZeroRotator;

DeltaRotation.Yaw = Value*TurnRate* UGameplayStatics::GetWorldDeltaSeconds(this);

AddActorLocalRotation(DeltaRotation, true);

}

If you add a log in the move function is it coming up and with the correct values?

no, it does not say anything, and i have compiled succesfully so i dont know was going on


here is the code

#include "Tank.h"
#include "GameFramework/SpringArmComponent.h"
#include"Camera/CameraComponent.h"
#include "Components/InputComponent.h"
#include "Kismet/GameplayStatics.h"
#include "DrawDebugHelpers.h"
#include "GameFramework/PlayerController.h"

ATank::ATank()
{
    SpringArm = CreateDefaultSubobject<USpringArmComponent>(TEXT("SpringArm"));
    SpringArm -> SetupAttachment(RootComponent);
    Camera = CreateDefaultSubobject<UCameraComponent>(TEXT("Camera"));
    Camera -> SetupAttachment(SpringArm);
}

void ATank::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
    Super::SetupPlayerInputComponent(PlayerInputComponent);

    PlayerInputComponent -> BindAxis(TEXT("MoveFoward"), this, &ATank::Move);
    PlayerInputComponent -> BindAxis(TEXT("Turn"), this, &ATank::Turn);
    PlayerInputComponent -> BindAction(TEXT("Fire"), IE_Pressed, this, &ATank::Fire);
}

void ATank::Tick(float DeltaTime)
{
    Super::Tick(DeltaTime);

    FHitResult HitResult;
    if(TankPlayerController)
    {
        TankPlayerController -> GetHitResultUnderCursor(ECollisionChannel::ECC_Visibility, false, HitResult);
        RotateTurret(HitResult.ImpactPoint);
    }
}

void ATank::HandleDestruction()
{
    Super::HandleDestruction();

    SetActorHiddenInGame(true);
    SetActorTickEnabled(false);
}

void ATank::BeginPlay()
{
    Super::BeginPlay();

    TankPlayerController = Cast<APlayerController>(GetController());
}

void ATank::Move(float Value)
{
    FVector DeltaLocation = FVector::ZeroVector;

    DeltaLocation.X = Value * Speed * UGameplayStatics::GetWorldDeltaSeconds(this);
    AddActorLocalOffset(DeltaLocation, true);
    UE_LOG(LogTemp, Warning, TEXT("Moving"));
}

void ATank::Turn(float Value)
{
    FRotator DeltaRotation = FRotator::ZeroRotator;
    DeltaRotation.Yaw = Value*TurnRate* UGameplayStatics::GetWorldDeltaSeconds(this);
    AddActorLocalRotation(DeltaRotation, true);
}

You are not showing the output log which you can open via the Window menu, the bottom left next to the console command, or via the keyboard shortcut Alt + ` (that is a backtick not an apostrophe, it’s the key next to 1).


when i press the keys it does not show the text

By any chance was this working previously but stopped working after creating those widgets?

no the tank did not move from the beggining

so i dont think the widgets are the problem

Ah, looks like you have a spelling mistake here. Missing r in foRward.


I corrected the spelling mistake and still not showing the text maybe it could be an option to enable input in the pawn that i dont know?

UPDATE: it seems that i forgot to slect Tank as the parent class of the pawn so it was totally my fault thanks for the help dan and sorry

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.