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 FOVScale=0.011110
DoubleClickTime=0.200000 DoubleClickTime=0.200000
+ActionMappings=(ActionName="Fire",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=LeftMouseButton) +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=4.000000,Key=W)
+AxisMappings=(AxisName="MoveForward",Scale=-1.000000,Key=S) +AxisMappings=(AxisName="MoveForward",Scale=-4.000000,Key=S)
+AxisMappings=(AxisName="Turn",Scale=1.000000,Key=D) +AxisMappings=(AxisName="Turn",Scale=4.000000,Key=D)
+AxisMappings=(AxisName="Turn",Scale=-1.000000,Key=A) +AxisMappings=(AxisName="Turn",Scale=-4.000000,Key=A)
+AxisMappings=(AxisName="RotateTurret",Scale=1.000000,Key=MouseX) +AxisMappings=(AxisName="RotateTurret",Scale=1.000000,Key=MouseX)
DefaultPlayerInputClass=/Script/EnhancedInput.EnhancedPlayerInput DefaultPlayerInputClass=/Script/EnhancedInput.EnhancedPlayerInput
DefaultInputComponentClass=/Script/EnhancedInput.EnhancedInputComponent DefaultInputComponentClass=/Script/EnhancedInput.EnhancedInputComponent

Binary file not shown.

View File

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

View File

@@ -61,7 +61,4 @@ public:
// Called every frame // Called every frame
virtual void Tick(float DeltaTime) override; 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 "Tank.h"
#include "GameFramework/SpringArmComponent.h" #include "GameFramework/SpringArmComponent.h"
#include "Camera/CameraComponent.h" #include "Camera/CameraComponent.h"
#include "Components/InputComponent.h"
ATank::ATank() ATank::ATank()
{ {
SpringArm = CreateDefaultSubobject<USpringArmComponent>(TEXT("Spring Arm")); SpringArm = CreateDefaultSubobject<USpringArmComponent>(TEXT("Spring Arm"));
SpringArm->SetupAttachment(RootComponent); SpringArm->SetupAttachment(RootComponent);
Camera = CreateDefaultSubobject<UCameraComponent>(TEXT("Camera")); Camera = CreateDefaultSubobject<UCameraComponent>(TEXT("Camera"));
Camera->SetupAttachment(SpringArm); 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: public:
ATank(); ATank();
// Called to bind functionality to input
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
private: private:
UPROPERTY(VisibleAnywhere, Category = "Components") UPROPERTY(VisibleAnywhere, Category = "Components")
class USpringArmComponent* SpringArm; class USpringArmComponent* SpringArm;
UPROPERTY(VisibleAnywhere, Category = "Components") UPROPERTY(VisibleAnywhere, Category = "Components")
class UCameraComponent* Camera; class UCameraComponent* Camera;
void Move(float Value);
void Turn(float TValue);
}; };