LEAP Documentation 40220
Documentation for the LEAP project
PXProjectileMovementComponent.h
Go to the documentation of this file.
1// Copyright Blue Isle Studios Inc 2018. All Rights Reserved.
2
3#pragma once
4
5#include "CoreMinimal.h"
6#include "GameFramework/MovementComponent.h"
8#include "PXProjectileMovementComponent.generated.h"
9
10DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FAccelerateTowardsHomingSignature, bool, bIsAccelerating);
11
12UENUM(BlueprintType)
13enum class EQualityMode : uint8
14{
15 High = 0,
16 Medium = 1,
17 Low = 2
18};
19
20#define MED_QUALITY_DIST 25000.f
21#define LOW_QUALITY_DIST 50000.f
22
23UCLASS(meta = (BlueprintSpawnableComponent))
24class PROJECTX_API UPXProjectileMovementComponent : public UMovementComponent, public IObjectPoolInterface
25{
26 GENERATED_UCLASS_BODY()
27
28public:
29 // Called after the class has had its configuration set by projectile.cpp
30 virtual void Init();
31 virtual void TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction *ThisTickFunction) override;
32 virtual void OnReleasedToObjectPool() override;
33 //~ End ActorComponent Interface
34
35 UFUNCTION(BlueprintCallable, Category = Projectile)
36 float GetSpeed() const { return Speed; }
37 UFUNCTION(BlueprintCallable, Category = Projectile)
38 float CanBounce() const { return bCanBounce; }
39 UFUNCTION()
40 bool IsHomingProjectile() const { return bIsHomingProjectile; }
41 UFUNCTION(BlueprintCallable, Category = Projectile)
42 bool IsDebug() const { return bDebug; }
43 UFUNCTION(BlueprintCallable, Category = Projectile)
44 EQualityMode GetQualityMode() const { return QualityMode; }
45 UFUNCTION(BlueprintCallable, Category = Projectile)
46 bool UseExtentTrace() const { return bUseExtentTrace && ProjectileExtent > 0.f; }
47 bool IsProjectileDestroyOnHit() const { return bStopOnDamageableHit; }
48
49 UFUNCTION(BlueprintCallable, Category = Projectile)
50 void SetMaxSpeed(float InMaxSpeed) { MaxSpeed = InMaxSpeed; Speed = MaxSpeed; }
51 UFUNCTION(BlueprintCallable, Category = Projectile)
52 void SetHomingTarget(USceneComponent* Target) { HomingTargetComponent = Target; }
53 UFUNCTION(BlueprintCallable, Category = Projectile)
54 void SetAimTarget(USceneComponent* Target, float Falloff) { AimTargetComponent = Target; AimTargetFalloff = Falloff; }
55
56protected:
57 virtual void PerformMovement(const float& DeltaTime);
58
59 bool ShouldIgnoreFriendlyTarget(const TArray<FHitResult>& Hits) const;
60 FVector GetProjectileInitialDirection() const;
61 virtual FVector ComputeHomingAcceleration(float DeltaTime) const;
62
63 virtual EQualityMode GetCurrentQualityLevel();
64
65 //Updates the quality level of this projectile.
66 virtual void UpdateQualityLevel();
67
68 static FVector CalculateReflectionVector(const FVector& Direction, const FVector& ImpactNormal);
69
70 virtual void NotifyHit(const FHitResult& Hit);
71
72 //Plays bullet whip if applicable
73 virtual void ApplyBulletWhip(float DeltaTime, const FVector& Start);
74
75protected:
76 UPROPERTY()
77 float Speed = 0.f;
78 UPROPERTY()
79 float MaxSpeed = 0.f;
80
81 UPROPERTY(EditDefaultsOnly, Category = Projectile)
82 bool bDebug = false;
83 UPROPERTY(EditDefaultsOnly, Category = Projectile)
84 float GravityScale = 1.f;
85
86 UPROPERTY(EditDefaultsOnly, Category = Projectile)
87 float ProjectileExtent = 0.f;
88
89 UPROPERTY(EditDefaultsOnly, Category = Projectile)
90 USoundBase* BulletWhipSound = NULL;
91 UPROPERTY(EditDefaultsOnly, Category = Projectile)
92 float BulletWhipSoundDistance = 500.f;
93 UPROPERTY()
94 bool bHasPlayedBulletWhip = false;
95
96 /* Determines if movement will use an extent trace. */
97 UPROPERTY()
98 bool bUseExtentTrace = false;
99
100 UPROPERTY(EditDefaultsOnly, Category = Projectile)
101 bool bCanBounce = false;
102 /* Pass false if you want the projectile to detonate on its using a timer or other mean. */
103 UPROPERTY(EditDefaultsOnly, Category = Projectile)
104 bool bStopOnDamageableHit = true;
105
106 UPROPERTY(EditDefaultsOnly, Category = Projectile)
107 float BounceSpeedMultiplier = 0.5;
108
109 UPROPERTY(EditDefaultsOnly, Category = Projectile)
110 bool bIsHomingProjectile = false;
111 UPROPERTY(EditDefaultsOnly, Category = Projectile)
112 float HomingAccelerationMagnitude = 0.f;
113 /* The maximum dot between the direction towards the homing target and our velocity in order to this projectile to accelerate towards the target */
114 UPROPERTY(EditDefaultsOnly, Category = Projectile)
115 float MaxHomingDotDeviation = .25f;
116
117 TArray<TWeakObjectPtr<AActor>> IgnoredActors;
118 TWeakObjectPtr<USceneComponent> HomingTargetComponent = nullptr;
119 TWeakObjectPtr<USceneComponent> AimTargetComponent = nullptr;
120 float AimTargetFalloff = 1.0f;
121
122 UPROPERTY()
123 bool bIsLocallyControlled = false;
124
125 UPROPERTY()
126 EQualityMode QualityMode = EQualityMode::High;
127
128 UPROPERTY()
129 TSubclassOf<class UWeaponInstanceRanged> OwningWeapon = nullptr;
130
131public:
132 friend class AProjectile;
133
134 FAccelerateTowardsHomingSignature AcceleratingTowardsHomingTargetDelegate;
135
136 bool bUpdateRotation = true;
137
138private:
139 FCollisionQueryParams CQP;
140};
EQualityMode
Definition: PXProjectileMovementComponent.h:14
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FAccelerateTowardsHomingSignature, bool, bIsAccelerating)
Definition: Projectile.h:18
Definition: ObjectPoolInterface.h:16
Definition: PXProjectileMovementComponent.h:25
bool IsProjectileDestroyOnHit() const
Definition: PXProjectileMovementComponent.h:47
Definition: WeaponInstanceRanged.h:27