#include "CentralizedPoint.h" #include "GameFramework/Character.h" ACentralizedPoint::ACentralizedPoint() { // Allow the object to tick PrimaryActorTick.bCanEverTick = true; } ACentralizedPoint::~ACentralizedPoint() { } void ACentralizedPoint::BeginPlay() { Super::BeginPlay(); } void ACentralizedPoint::Tick(float DeltaTime) { Super::Tick(DeltaTime); if (RefActor1 && RefActor2) { // Find the middle point between the two players FVector MiddlePoint = FindMiddlePoint(RefActor1, RefActor2); SetActorLocation(MiddlePoint); } } FVector ACentralizedPoint::FindMiddlePoint(AActor* Point1, AActor* Point2) { // Get the location of the two actors FVector Gubbe1Location = Point1->GetActorLocation(); FVector Gubbe2Location = Point2->GetActorLocation(); // Offsets vertical position if a character is crouching, so that the middle point doesn't go downwards if(dynamic_cast(Point1)->bIsCrouched) { Gubbe1Location += FVector(0, 0, CrouchMitigationOffset); } if(dynamic_cast(Point2)->bIsCrouched) { Gubbe2Location += FVector(0, 0, CrouchMitigationOffset); } // Calculate the middle point FVector MiddlePoint = (Gubbe1Location + Gubbe2Location) / 2; return MiddlePoint; } // Test comment