Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "BuildingEscape.h"
- #include "OpenDoor.h"
- #define OUT
- // Sets default values for this component's properties
- UOpenDoor::UOpenDoor()
- {
- // Set this component to be initialized when the game starts, and to be ticked every frame. You can turn these features
- // off to improve performance if you don't need them.
- PrimaryComponentTick.bCanEverTick = true;
- if (!PressurePlate)
- {
- UE_LOG(LogTemp, Error, TEXT("%s missing pressure plate"), *Owner->GetName())
- }
- }
- // Called when the game starts
- void UOpenDoor::BeginPlay()
- {
- Super::BeginPlay();
- Owner = GetOwner();
- }
- void UOpenDoor::OpenDoor()
- {
- // Set the door rotation
- Owner->SetActorRotation(FRotator(0.f, OpenAngle, 0.f));
- }
- void UOpenDoor::CloseDoor()
- {
- // Set the door rotation
- Owner->SetActorRotation(FRotator(0.f, 0.f, 0.f));
- }
- // Called every frame
- void UOpenDoor::TickComponent( float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction )
- {
- Super::TickComponent( DeltaTime, TickType, ThisTickFunction );
- // Poll the Trigger Volume
- if (GetTotalMassOfActorsOnPlate() > 30.f) // TODO make into a parameter
- {
- OpenDoor();
- LastDoorOpenTime = GetWorld()->GetTimeSeconds();
- }
- // Check if it's time to close the door
- if (GetWorld()->GetTimeSeconds() - LastDoorOpenTime >= DoorCloseDelay)
- {
- CloseDoor();
- }
- }
- float UOpenDoor::GetTotalMassOfActorsOnPlate()
- {
- float TotalMass = 0.f;
- // Find all the overlapping actors
- TArray<AActor*> OverlappingActors;
- if (!PressurePlate) { return TotalMass; }
- PressurePlate->GetOverlappingActors(OUT OverlappingActors);
- // Iterate through them, adding their masses
- for (const auto* Actor : OverlappingActors)
- {
- UE_LOG(LogTemp, Warning, TEXT("%s on pressure plate"), *Actor->GetName())
- TotalMass += Actor->FindComponentByClass<UPrimitiveComponent>()->GetMass();
- }
- return TotalMass;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement