LEAP Documentation 40220
Documentation for the LEAP project
Pickup.h
Go to the documentation of this file.
1//Copyright BIS 2022
2
3#pragma once
4
5#include "CoreMinimal.h"
6#include "GameFramework/Actor.h"
7#include "Pickup.generated.h"
8
9class UProjectileMovementComponent;
10class USphereComponent;
11class UStaticMeshComponent;
12
13UCLASS()
14class PROJECTX_API APickup : public AActor
15{
16 GENERATED_BODY()
17
18public:
19 APickup();
20
21 virtual void BeginPlay() override;
22
23 int32 GetPickupID() const { return PickupID; }
24 void SetPickupInfo(int32 InPickupID, FVector InExpectedTargetLocation) {PickupID = InPickupID; ExpectedTargetLocation = InExpectedTargetLocation; }
25
26 UFUNCTION()
27 void OnComponentBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);
28 UFUNCTION(BlueprintImplementableEvent, BlueprintCallable)
29 void OnItemPickedUp(AActor* OtherActor);
30 UFUNCTION(BlueprintNativeEvent, BlueprintCallable)
31 bool CanPickup(AProjectXCharacter* Player);
32
33 float GetMaxPickupDistance() const { return MaxPickupDistance; }
34
35protected:
36 /*virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override;*/
37 virtual void Tick(float DeltaTime) override;
38
39 /*Max distance (in cms) a pickup can be in order to be able to be picked up*/
40 UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Pickup")
41 float MaxPickupDistance = 500.0f;
42 /*The intensity of the random torque we apply to this pickup when spawned */
43 UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Pickup")
44 float SpawnTorqueIntensity = 500.0f;
45 /*The max number of corrections we allow until we start doing our manual and final correction*/
46 UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Pickup|Movement")
47 int MaxNumberOfCorrections = 6;
48 /*The time (in seconds) we allow the physics to run while being outside the pick-up radius, after that we're manually going to shift it towards the radius and let the physics simulate after it's there*/
49 UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Pickup|Movement")
50 int MaxAllowedTimeToReachPickupRadius = 4;
51 /* The intensity of the force we apply to help guide the movement towards the drop placement */
52 UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Pickup|Movement")
53 float HelpingForceIntensity = 500.0f;
54 /*When correcting the pickup due to being out of bounds, with how much intensity should we try to apply a correction force?*/
55 UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Pickup|Movement")
56 float OutOfBoundsCorrectionIntensity = 500.0f;
57 /*When correcting the pickup due to being out of bounds, we add a random rotation to give it some flair, how strong should that rotation be? */
58 UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Pickup|Movement")
59 float OutOfBoundsRandomRotationIntensity = 500.0f;
60 /* If we couldn't reach the pickup radius in time, how quickly should we interpolate towards the expected position? */
61 UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Pickup|Movement")
62 float InterpToRadiusSpeed = 2.f;
63 /* During the final movement correction, what's the distance (in cms) threshold we should stop our movement */
64 UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Pickup|Movement")
65 int MinDistanceFromTargetToStopFinalCorrection = 100;
66 /* The magnitude of the velocities to check to validate see if this has settled or not X = Linear Velocity, Y = Angular Velocity (Degrees)*/
67 UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Pickup|Movement")
68 FVector2D SettleForcesCheck = FVector2D(5.f, 2.f);
69
70
71 //The component used for overlaps
72 UPROPERTY(EditDefaultsOnly, Category = Pickup)
73 USphereComponent* OverlapComponent = nullptr;
74
75 UPROPERTY(EditDefaultsOnly, Category = Pickup)
76 UStaticMeshComponent* StaticMeshComponent = nullptr;
77
78 UFUNCTION()
79 void OnWaitingToReachRadiusExpired();
80
81private:
82 int32 PickupID = 0;
83 FVector ExpectedTargetLocation = FVector::ZeroVector;
84 FTimerHandle PhysicsTimerHandle;
85 FTimerHandle WaitingToReachRadiusTimerHandle;
86 int CurrentNumberOfCorrections = 0;
87
88 FVector PreviousLocation = FVector::ZeroVector;
89 FRotator PreviousRotation = FRotator::ZeroRotator;
90
91 //We have entered the pickup radius and can now start to correct our placement out-of-bounds
92 bool bHasReachedPickupRadius = false;
93 //When under final correction, we've tried to corrected our position enough times and didn't get to a good enough resting position
94 bool bIsUnderFinalCorrection = false;
95 //Haven't reached the pickup radius within the allowed time
96 bool bIsInterpolatingToRadius = false;
97};
Definition: Pickup.h:15
void SetPickupInfo(int32 InPickupID, FVector InExpectedTargetLocation)
Definition: Pickup.h:24
int32 GetPickupID() const
Definition: Pickup.h:23
Definition: ProjectXCharacter.h:128