Advertisement
Guest User

OpenDoor.cpp

a guest
Oct 4th, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.89 KB | None | 0 0
  1. // Fill out your copyright notice in the Description page of Project Settings.
  2.  
  3. #include "BuildingEscape.h"
  4. #include "OpenDoor.h"
  5.  
  6. #define OUT
  7.  
  8. // Sets default values for this component's properties
  9. UOpenDoor::UOpenDoor() {
  10.     // Set this component to be initialized when the game starts, and to be ticked every frame.  You can turn these features
  11.     // off to improve performance if you don't need them.
  12.     PrimaryComponentTick.bCanEverTick = true;
  13. }
  14.  
  15.  
  16. // Called when the game starts
  17. void UOpenDoor::BeginPlay() {
  18.     Super::BeginPlay();
  19.     //OpenDoor();
  20.     Owner = GetOwner();
  21. }
  22.  
  23. void UOpenDoor::OpenDoor() {
  24.     //Set the door rotation
  25.     Owner->SetActorRotation(FRotator(0.0f, OpenAngle, 0.0f));
  26. }
  27.  
  28. void UOpenDoor::CloseDoor() {
  29.     //Set the door rotation
  30.     Owner->SetActorRotation(FRotator(0.0f, 0.0f, 0.0f));
  31. }
  32. // Called every frame
  33. void UOpenDoor::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) {
  34.     Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
  35.     // Poll the Trigger Volume every frame
  36.     //if ((PressurePlate->IsOverlappingActor(ActorThatOpens))&(PressurePlate2->IsOverlappingActor(ActorThatOpens2)))
  37.     if (GetTotalMassOfActorsOnPlate()>20.f) {
  38.         OpenDoor();
  39.         LastDoorOpenTime = GetWorld()->GetTimeSeconds();
  40.     }
  41.     //Check if it's time to close the door
  42.     if ((GetWorld()->GetTimeSeconds()) - LastDoorOpenTime > DoorCloseDelay) {
  43.         CloseDoor();
  44.     }
  45. }
  46.  
  47. float UOpenDoor::GetTotalMassOfActorsOnPlate(){
  48.     float TotalMass = 0.f;
  49.     //Find all the overlapping actors
  50.     TArray<AActor*> OverlappingActors;
  51.     PressurePlate->GetOverlappingActors(OUT OverlappingActors);
  52.     //Iterate through them adding their masses
  53.     for (const auto* Actor : OverlappingActors) {
  54.         TotalMass += Actor->FindComponentByClass<UPrimitiveComponent>()->GetMass();
  55.         UE_LOG(LogTemp, Warning, TEXT("%s on pressure plate"), *Actor->GetName());
  56.     }
  57.  
  58.     return TotalMass;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement