Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Fill out your copyright notice in the Description page of Project Settings.
- #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;
- }
- // Called when the game starts
- void UOpenDoor::BeginPlay() {
- Super::BeginPlay();
- //OpenDoor();
- Owner = GetOwner();
- }
- void UOpenDoor::OpenDoor() {
- //Set the door rotation
- Owner->SetActorRotation(FRotator(0.0f, OpenAngle, 0.0f));
- }
- void UOpenDoor::CloseDoor() {
- //Set the door rotation
- Owner->SetActorRotation(FRotator(0.0f, 0.0f, 0.0f));
- }
- // Called every frame
- void UOpenDoor::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) {
- Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
- // Poll the Trigger Volume every frame
- //if ((PressurePlate->IsOverlappingActor(ActorThatOpens))&(PressurePlate2->IsOverlappingActor(ActorThatOpens2)))
- if (GetTotalMassOfActorsOnPlate()>20.f) {
- 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;
- PressurePlate->GetOverlappingActors(OUT OverlappingActors);
- //Iterate through them adding their masses
- for (const auto* Actor : OverlappingActors) {
- TotalMass += Actor->FindComponentByClass<UPrimitiveComponent>()->GetMass();
- UE_LOG(LogTemp, Warning, TEXT("%s on pressure plate"), *Actor->GetName());
- }
- return TotalMass;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement