-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTank.cpp
61 lines (61 loc) · 2.2 KB
/
Tank.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include "Tank.h"
#include "GameFramework/SpringArmComponent.h"
#include "Camera/CameraComponent.h"
#include "Kismet/GameplayStatics.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);
PlayerInputComponent->BindAction(TEXT("FIRE"), IE_Pressed, this, &ATank::Fire);
}
void ATank::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
if (TankPlayerController)
{
FHitResult HitResult;
TankPlayerController->GetHitResultUnderCursor(
ECollisionChannel::ECC_Visibility,
false,
HitResult);
//DrawDebugSphere(GetWorld(), HitResult.ImpactPoint, 25.f, 12, FColor::Red, false, -1.f);
RotateTurret(HitResult.ImpactPoint);
}
}
****************************************************************************************************
//Function of destruction
void ATank::HandleDestruction()
{
Super::HandleDestruction();
SetActorHiddenInGame(true);
SetActorTickEnabled(false);
bAlive = false;
}
// at begin play
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);
}
void ATank::Turn(float Value)
{
FRotator DeltaRotation = FRotator::ZeroRotator;
DeltaRotation.Yaw = Value * TurnRate * UGameplayStatics::GetWorldDeltaSeconds(this);
AddActorLocalRotation(DeltaRotation, true);
}
***This is much shorter version of code compared to previous one***