Tank Movement

This commit is contained in:
2025-07-17 02:13:16 -04:00
parent 8a36c7924a
commit 6a57c74661
6 changed files with 42 additions and 14 deletions

View File

@@ -87,10 +87,10 @@ DefaultViewportMouseLockMode=LockOnCapture
FOVScale=0.011110
DoubleClickTime=0.200000
+ActionMappings=(ActionName="Fire",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=LeftMouseButton)
+AxisMappings=(AxisName="MoveForward",Scale=1.000000,Key=W)
+AxisMappings=(AxisName="MoveForward",Scale=-1.000000,Key=S)
+AxisMappings=(AxisName="Turn",Scale=1.000000,Key=D)
+AxisMappings=(AxisName="Turn",Scale=-1.000000,Key=A)
+AxisMappings=(AxisName="MoveForward",Scale=4.000000,Key=W)
+AxisMappings=(AxisName="MoveForward",Scale=-4.000000,Key=S)
+AxisMappings=(AxisName="Turn",Scale=4.000000,Key=D)
+AxisMappings=(AxisName="Turn",Scale=-4.000000,Key=A)
+AxisMappings=(AxisName="RotateTurret",Scale=1.000000,Key=MouseX)
DefaultPlayerInputClass=/Script/EnhancedInput.EnhancedPlayerInput
DefaultInputComponentClass=/Script/EnhancedInput.EnhancedInputComponent

Binary file not shown.

View File

@@ -36,12 +36,8 @@ void ABasePawn::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
// Called to bind functionality to input
void ABasePawn::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
Super::SetupPlayerInputComponent(PlayerInputComponent);
/*FVector DeltaLocation(0.f);
DeltaLocation.X = 2.f;
AddActorLocalOffset(DeltaLocation);*/
}

View File

@@ -61,7 +61,4 @@ public:
// Called every frame
virtual void Tick(float DeltaTime) override;
// Called to bind functionality to input
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
};

View File

@@ -4,12 +4,41 @@
#include "Tank.h"
#include "GameFramework/SpringArmComponent.h"
#include "Camera/CameraComponent.h"
#include "Components/InputComponent.h"
ATank::ATank()
{
SpringArm = CreateDefaultSubobject<USpringArmComponent>(TEXT("Spring Arm"));
SpringArm->SetupAttachment(RootComponent);
Camera = CreateDefaultSubobject<UCameraComponent>(TEXT("Camera"));
Camera->SetupAttachment(SpringArm);
}
void ATank::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
Super::SetupPlayerInputComponent(PlayerInputComponent);
PlayerInputComponent->BindAxis(TEXT("MoveForward"), this, &ATank::Move);
PlayerInputComponent->BindAxis(TEXT("Turn"), this, &ATank::Turn);
}
void ATank::Move(float Value)
{
//FVector DeltaLocation(0.f); //Same as line below
FVector DeltaLocation = FVector::ZeroVector;
DeltaLocation.X = Value;
AddActorLocalOffset(DeltaLocation);
//UE_LOG(LogTemp, Warning, TEXT("Value: %f"), Value);
}
void ATank::Turn(float TValue)
{
//UE_LOG(LogTemp, Warning, TEXT("Value: %f"), TValue);
}

View File

@@ -17,10 +17,16 @@ class TOONTANKS_API ATank : public ABasePawn
public:
ATank();
// Called to bind functionality to input
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
private:
UPROPERTY(VisibleAnywhere, Category = "Components")
class USpringArmComponent* SpringArm;
UPROPERTY(VisibleAnywhere, Category = "Components")
class UCameraComponent* Camera;
void Move(float Value);
void Turn(float TValue);
};