-
Notifications
You must be signed in to change notification settings - Fork 0
/
SDashProjectile.cpp
74 lines (49 loc) · 1.96 KB
/
SDashProjectile.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
74
// Fill out your copyright notice in the Description page of Project Settings.
#include "SDashProjectile.h"
#include "Kismet/GameplayStatics.h"
#include "Particles/ParticleSystemComponent.h"
#include "GameFramework/ProjectileMovementComponent.h"
#include "Sound/SoundCue.h"
ASDashProjectile::ASDashProjectile()
{
TeleportDelay = 0.2f;
DetonateDelay = 0.2f;
MoveComp->InitialSpeed = 6000.f;
}
void ASDashProjectile::BeginPlay()
{
Super::BeginPlay();
GetWorldTimerManager().SetTimer(TimerHandle_DelayedDetonate, this, &ASDashProjectile::Explode, DetonateDelay);
}
void ASDashProjectile::Explode_Implementation()
{
// Clear timer if the Explode was already called through another source like OnActorHit
GetWorldTimerManager().ClearTimer(TimerHandle_DelayedDetonate);
UGameplayStatics::SpawnEmitterAtLocation(this, ImpactVFX, GetActorLocation(), GetActorRotation());
UGameplayStatics::PlaySoundAtLocation(this, ImpactSound, GetActorLocation());
EffectComp->DeactivateSystem();
MoveComp->StopMovementImmediately();
SetActorEnableCollision(false);
FTimerHandle TimerHandle_DelayedTeleport;
GetWorldTimerManager().SetTimer(TimerHandle_DelayedTeleport, this, &ASDashProjectile::TeleportInstigator, TeleportDelay);
// Skip base implementation as it will destroy actor (we need to stay alive a bit longer to finish the 2nd timer)
//Super::Explode_Implementation();
}
void ASDashProjectile::TeleportInstigator()
{
AActor* ActorToTeleport = GetInstigator();
if (ensure(ActorToTeleport))
{
// Keep instigator rotation or it may end up jarring
ActorToTeleport->TeleportTo(GetActorLocation(), ActorToTeleport->GetActorRotation(), false, false);
// Play shake on the player we teleported
APawn* InstigatorPawn = Cast<APawn>(ActorToTeleport);
APlayerController* PC = Cast<APlayerController>(InstigatorPawn->GetController());
if (PC && PC->IsLocalController())
{
PC->ClientStartCameraShake(ImpactShake);
}
}
// Now we're ready to destroy self
Destroy();
}