-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBasePawn.cpp
73 lines (72 loc) · 2.7 KB
/
BasePawn.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
62
63
64
65
66
67
68
69
70
71
72
73
#include "BasePawn.h"
#include "Components/CapsuleComponent.h"
#include "Components/StaticMeshComponent.h"
#include "Kismet/GameplayStatics.h"
#include "Math/UnrealMathUtility.h"
#include "Projectile.h"
#include "Particles/ParticleSystem.h"
//#include "DrawDebugHelpers.h"
//the resaon drawdebugger has been commented is that when we click the shoot the sphere get popped up on the screen
// Sets default values
ABasePawn::ABasePawn()
{
// Set this pawn to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
CapsuleComp = CreateDefaultSubobject<UCapsuleComponent>(TEXT("Capsule Collider"));
RootComponent = CapsuleComp;
*******************************************************************************
BaseMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Base Mesh"));
BaseMesh->SetupAttachment(CapsuleComp);
**************************************************************************************
TurretMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Turret Mesh"));
TurretMesh->SetupAttachment(BaseMesh);
************************************************************************************************
ProjectileSpawnPoint = CreateDefaultSubobject<USceneComponent>(TEXT("Spawn Point"));
ProjectileSpawnPoint->SetupAttachment(TurretMesh);
}
/*date 1/16/24*/
/*commmiting changes*/
void ABasePawn::HandleDestruction()
{
if (DeathParticles)
{
UGameplayStatics::SpawnEmitterAtLocation(this, DeathParticles, GetActorLocation(), GetActorRotation());
}
if (DeathSound)
{
UGameplayStatics::PlaySoundAtLocation(this, DeathSound, GetActorLocation());
}
if (DeathCameraShakeClass)
{
GetWorld()->GetFirstPlayerController()->ClientStartCameraShake(DeathCameraShakeClass);
}
}
void ABasePawn::RotateTurret(FVector LookAtTarget)
{
FVector ToTarget = LookAtTarget - TurretMesh->GetComponentLocation();
FRotator LookAtRotation = FRotator(0.f,ToTarget.Rotation().Yaw, 0.f);
TurretMesh->SetWorldRotation(
FMath::RInterpTo(
TurretMesh->GetComponentRotation(),
LookAtRotation,
UGameplayStatics::GetWorldDeltaSeconds(this),
5.f)
);
}
void ABasePawn::Fire()
{
FVector Location = ProjectileSpawnPoint->GetComponentLocation();
FRotator Rotation = ProjectileSpawnPoint->GetComponentRotation();
*********************************************************************
AProjectile* Projectile = GetWorld()->SpawnActor<AProjectile>(ProjectileClass, Location, Rotation);
Projectile->SetOwner(this);
//DrawDebugSphere(
// GetWorld(),
// Location,
// 25.f,
// 12,
// FColor::Red,
// false,
// 3.f);
}
/*Changes required were done after the querires were posted*/