door opens!!!
This commit is contained in:
parent
b7be0494d7
commit
1c59557023
Binary file not shown.
@ -2,8 +2,11 @@
|
|||||||
|
|
||||||
#include "OpenDoor.h"
|
#include "OpenDoor.h"
|
||||||
#include "Engine/World.h"
|
#include "Engine/World.h"
|
||||||
|
#include "Components/PrimitiveComponent.h"
|
||||||
#include "GameFramework/Actor.h" // See auto completes
|
#include "GameFramework/Actor.h" // See auto completes
|
||||||
|
|
||||||
|
#define OUT
|
||||||
|
|
||||||
|
|
||||||
// Sets default values for this component's properties
|
// Sets default values for this component's properties
|
||||||
UOpenDoor::UOpenDoor()
|
UOpenDoor::UOpenDoor()
|
||||||
@ -21,17 +24,37 @@ void UOpenDoor::BeginPlay()
|
|||||||
Super::BeginPlay();
|
Super::BeginPlay();
|
||||||
OwningDoor = GetOwner();
|
OwningDoor = GetOwner();
|
||||||
|
|
||||||
ActorThatOpens = GetWorld()->GetFirstPlayerController()->GetPawn();
|
}
|
||||||
|
|
||||||
|
//Returns total mass in Kg
|
||||||
|
float UOpenDoor::GetTotalMassOfActorsOnPlate()
|
||||||
|
{
|
||||||
|
float TotalMass = 0.0f;
|
||||||
|
|
||||||
|
TArray<AActor*> OverlappingActors;
|
||||||
|
|
||||||
|
//Find all overlapping actors.
|
||||||
|
PressurePlate->GetOverlappingActors(
|
||||||
|
OUT OverlappingActors
|
||||||
|
);
|
||||||
|
//iterate through finding masses.
|
||||||
|
for (const auto *Actor : OverlappingActors) {
|
||||||
|
UPrimitiveComponent *Component = Actor->FindComponentByClass<UPrimitiveComponent>();
|
||||||
|
TotalMass += Component->GetMass();
|
||||||
|
|
||||||
|
UE_LOG(LogTemp, Warning, TEXT("MASS %s"), *Actor->GetName());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return TotalMass;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void UOpenDoor::OpenDoor() {
|
void UOpenDoor::OpenDoor() {
|
||||||
FString Rot = OwningDoor->GetTransform().GetRotation().GetAxisZ().ToString();
|
|
||||||
OwningDoor->SetActorRotation(FRotator(0.0f, OpenAngle, 0.0f));
|
OwningDoor->SetActorRotation(FRotator(0.0f, OpenAngle, 0.0f));
|
||||||
}
|
}
|
||||||
|
|
||||||
void UOpenDoor::CloseDoor() {
|
void UOpenDoor::CloseDoor() {
|
||||||
FString Rot = OwningDoor->GetTransform().GetRotation().GetAxisZ().ToString();
|
|
||||||
OwningDoor->SetActorRotation(FRotator(0.0f, 0.0f, 0.0f));
|
OwningDoor->SetActorRotation(FRotator(0.0f, 0.0f, 0.0f));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -42,7 +65,7 @@ void UOpenDoor::TickComponent(float DeltaTime, ELevelTick TickType, FActorCompon
|
|||||||
float CurSeconds = GetWorld()->GetTimeSeconds();
|
float CurSeconds = GetWorld()->GetTimeSeconds();
|
||||||
// poll the TriggerVolume every frame
|
// poll the TriggerVolume every frame
|
||||||
// if ActorThatOpens is in the volume, open door
|
// if ActorThatOpens is in the volume, open door
|
||||||
if (PressurePlate->IsOverlappingActor(ActorThatOpens)) {
|
if (GetTotalMassOfActorsOnPlate() > TriggerMass) {
|
||||||
OpenDoor();
|
OpenDoor();
|
||||||
LastDoorOpenTime = CurSeconds;
|
LastDoorOpenTime = CurSeconds;
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,9 @@ private:
|
|||||||
UPROPERTY(EditAnywhere)
|
UPROPERTY(EditAnywhere)
|
||||||
float OpenAngle = -90.f;
|
float OpenAngle = -90.f;
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere)
|
||||||
|
float TriggerMass = 50.f;
|
||||||
|
|
||||||
UPROPERTY(EditAnywhere)
|
UPROPERTY(EditAnywhere)
|
||||||
ATriggerVolume* PressurePlate;
|
ATriggerVolume* PressurePlate;
|
||||||
|
|
||||||
@ -37,8 +40,9 @@ private:
|
|||||||
|
|
||||||
float LastDoorOpenTime;
|
float LastDoorOpenTime;
|
||||||
|
|
||||||
AActor* ActorThatOpens;
|
|
||||||
AActor* OwningDoor;
|
AActor* OwningDoor;
|
||||||
|
|
||||||
|
float GetTotalMassOfActorsOnPlate();
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user