[3/50] Reusable Pressure Plates with C++

Pressure plates are objects on which the player can step on or move other objects over them to trigger certain events.
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FRiddlePressureSolvedDelegate);
UCLASS()
class ARiddlePressurePlate : public AActor
{
GENERATED_BODY()
public:
UPROPERTY(VisibleAnywhere, BlueprintReadWrite)
class UBoxComponent* CollisionBox;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
FGameplayTagContainer GameplayTags;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
UStaticMeshComponent* StaticMeshComponent;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "LostFerry")
bool OneTime;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "LostFerry")
FText Text;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "LostFerry")
FGameplayTag SolutionTag;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "LostFerry")
class USoundWave* Audio;
void OnPlayerInteract(ACharacter* PlayerCharacter) override;
UFUNCTION(BlueprintCallable, Category = "LostFerry")
bool CanPlayerSolve(ACharacter* PlayerCharacter);
UFUNCTION(BlueprintCallable, Category = "LostFerry")
void SolveWithPlayer(ACharacter* PlayerCharacter);
UPROPERTY(BlueprintAssignable, Category = "LostFerry")
FRiddlePressureSolvedDelegate OnRiddleSolved;
};
Here we declare the basic components of a pressure plate mechanic including the collision box and the static mesh component that is rendered as the pressure plate. The flag bOneTime
is declare if the pressure plate can be triggered more than once or not.
The implementation is again very simple. We look for the collision and check if the player has the solution tag with a guard for one time. In addition, we play the audio, USoundWave* Audio
and display the FText Text
but these can be dependent on the micro design of the mechanic.