My Take on the Close Door

Slightly Different Take for closing the door

OpenDoor.h

	UPROPERTY(EditAnywhere)
	float DoorCloseDelay = 1.0f;
	float CurDoorCloseDelay =  -1.0f; 

	AActor* ActorThatOpens; 
	AActor* Owner; // The owning door

OpenDoor.cpp

// Called every frame
void UOpenDoor::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
	Super::TickComponent(DeltaTime, TickType, ThisTickFunction);

	// polling The trigger volume (not good use events sytem insted
	// If the actor that opens a door is in the volume
	if (PressurePlate->IsOverlappingActor(ActorThatOpens))
	{
		OpenDoor();
		CurDoorCloseDelay = 0.0f;
	}

	// if cur door close delay is a 0 or positive value
	if (CurDoorCloseDelay >= 0.0f)
	{
		CurDoorCloseDelay += DeltaTime;
		// Check if close delay has reached the delay time to close the door
		if (CurDoorCloseDelay >= DoorCloseDelay)
		{
			CloseDoor();
			CurDoorCloseDelay = -1.0f;
		}
	}
}

Privacy & Terms