-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWeapon_projectile.cpp
70 lines (49 loc) · 1.44 KB
/
Weapon_projectile.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
#include "MutantSurvival.h"
#include "Weapon.h"
#include "Bullet.h"
#include "Weapon_projectile.h"
AWeapon_projectile::AWeapon_projectile(const class FPostConstructInitializeProperties& PCIP)
: Super(PCIP)
{
}
void AWeapon_projectile::execFire(){
//GetComponentByClass()
if (bullets > 0){
SpawnParams.Owner = this;
SpawnParams.Instigator = hero->Instigator;
hero->GetActorEyesViewPoint(CameraLoc, CameraRot);
MuzzleLocation = CameraLoc + FTransform(CameraRot).TransformVector(MuzzleOffset);
MuzzleRotation = CameraRot;
GEngine->AddOnScreenDebugMessage(-1, 5.0, FColor::Green, FString::FString("UWOT"));
if (ProjectileClass != NULL){
UWorld* const World = GetWorld();
if (World)
{
// spawn the projectile at the muzzle
MuzzleLocation.Z = MuzzleLocation.Z + 10;
ABullet* const Projectile = World->SpawnActor<ABullet>(ProjectileClass, MuzzleLocation, MuzzleRotation, SpawnParams);
bullets--;
if (Projectile)
{
GEngine->AddOnScreenDebugMessage(-1, 5.0, FColor::Green, FString::FString("SPAWN SUCESSFUL"));
// find launch direction
FVector LaunchDir = MuzzleRotation.Vector();
Projectile->InitVelocity(LaunchDir);
}
}
}
if (firing){
GetWorldTimerManager().SetTimer(this, &AWeapon_projectile::execFire, 60 / FireRate, false);
}
}
else{
if (mag > 0){
bullets = clipSize;
mag--;
}
}
}
void AWeapon_projectile::fire(AActor *hero){
this->hero = hero;
execFire();
}