Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions Content/AC_RTSCameraFollowMe.uasset

This file was deleted.

4 changes: 2 additions & 2 deletions Content/BP_RTSCamera.uasset
Git LFS file not shown
1 change: 0 additions & 1 deletion OpenRTSCamera.uplugin
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"Description": "An Unreal Engine 5 open-source RTS/MOBA camera implementation that aims to be fully featured, customizable and dependable",
"DocsURL": "https://github.com/HeyZoos/OpenRTSCamera/wiki",
"EnabledByDefault": true,
"EngineVersion": "5.3.0",
"FileVersion": 3,
"FriendlyName": "OpenRTSCamera",
"Installed": false,
Expand Down
29 changes: 20 additions & 9 deletions Source/OpenRTSCamera/Private/RTSCamera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ URTSCamera::URTSCamera()
this->CameraBlockingVolumeTag = FName("OpenRTSCamera#CameraBounds");
this->CollisionChannel = ECC_WorldStatic;
this->DragExtent = 0.6f;
this->EdgeScrollSpeed = 50;
this->DistanceFromEdgeThreshold = 0.1f;
this->EnableCameraLag = true;
this->EnableCameraRotationLag = true;
Expand All @@ -26,7 +25,9 @@ URTSCamera::URTSCamera()
this->FindGroundTraceLength = 100000;
this->MaximumZoomLength = 5000;
this->MinimumZoomLength = 500;
this->MoveSpeed = 50;
this->MaxMoveSpeed = 1024.0f;
this->MinMoveSpeed = 128.0f;
this->NowMoveSpeed = this->MinMoveSpeed; // Initialize NowMoveSpeed to MinMoveSpeed
this->RotateSpeed = 45;
this->StartingYAngle = -45.0f;
this->StartingZAngle = 0;
Expand Down Expand Up @@ -74,6 +75,8 @@ void URTSCamera::BeginPlay()
this->CheckForEnhancedInputComponent();
this->BindInputMappingContext();
this->BindInputActions();


}
}

Expand All @@ -88,6 +91,9 @@ void URTSCamera::TickComponent(
if (NetMode != NM_DedicatedServer && this->PlayerController->GetViewTarget() == this->Owner)
{
this->DeltaSeconds = DeltaTime;



this->ApplyMoveCameraCommands();
this->ConditionallyPerformEdgeScrolling();
this->ConditionallyKeepCameraAtDesiredZoomAboveGround();
Expand All @@ -96,7 +102,6 @@ void URTSCamera::TickComponent(
this->ConditionallyApplyCameraBounds();
}
}

void URTSCamera::FollowTarget(AActor* Target)
{
this->CameraFollowTarget = Target;
Expand All @@ -114,6 +119,12 @@ void URTSCamera::OnZoomCamera(const FInputActionValue& Value)
this->MinimumZoomLength,
this->MaximumZoomLength
);

// Calculate Alpha for Lerp (0 at min zoom, 1 at max zoom)
float Alpha = (this->DesiredZoomLength - this->MinimumZoomLength) / (this->MaximumZoomLength - this->MinimumZoomLength);

// Lerp NowMoveSpeed between MinMoveSpeed and MaxMoveSpeed
this->NowMoveSpeed = FMath::Lerp(this->MinMoveSpeed, this->MaxMoveSpeed, Alpha);
}

void URTSCamera::OnRotateCamera(const FInputActionValue& Value)
Expand Down Expand Up @@ -228,7 +239,7 @@ void URTSCamera::ApplyMoveCameraCommands()
{
auto Movement = FVector2D(X, Y);
Movement.Normalize();
Movement *= this->MoveSpeed * Scale * this->DeltaSeconds;
Movement *= this->NowMoveSpeed * Scale * this->DeltaSeconds;
this->Root->SetWorldLocation(
this->Root->GetComponentLocation() + FVector(Movement.X, Movement.Y, 0.0f)
);
Expand All @@ -248,7 +259,7 @@ void URTSCamera::CollectComponentDependencyReferences()

void URTSCamera::ConfigureSpringArm()
{
this->DesiredZoomLength = this->MaximumZoomLength;
this->DesiredZoomLength = this->MinimumZoomLength;
this->SpringArm->TargetArmLength = this->DesiredZoomLength;
this->SpringArm->bDoCollisionTest = false;
this->SpringArm->bEnableCameraLag = this->EnableCameraLag;
Expand Down Expand Up @@ -424,7 +435,7 @@ void URTSCamera::EdgeScrollLeft() const
const auto Movement = UKismetMathLibrary::FClamp(NormalizedMousePosition, 0.0, 1.0);

this->Root->AddRelativeLocation(
-1 * this->Root->GetRightVector() * Movement * this->EdgeScrollSpeed * this->DeltaSeconds
-1 * this->Root->GetRightVector() * Movement * this->NowMoveSpeed * this->DeltaSeconds
);
}

Expand All @@ -440,7 +451,7 @@ void URTSCamera::EdgeScrollRight() const

const auto Movement = UKismetMathLibrary::FClamp(NormalizedMousePosition, 0.0, 1.0);
this->Root->AddRelativeLocation(
this->Root->GetRightVector() * Movement * this->EdgeScrollSpeed * this->DeltaSeconds
this->Root->GetRightVector() * Movement * this->NowMoveSpeed * this->DeltaSeconds
);
}

Expand All @@ -456,7 +467,7 @@ void URTSCamera::EdgeScrollUp() const

const auto Movement = 1 - UKismetMathLibrary::FClamp(NormalizedMousePosition, 0.0, 1.0);
this->Root->AddRelativeLocation(
this->Root->GetForwardVector() * Movement * this->EdgeScrollSpeed * this->DeltaSeconds
this->Root->GetForwardVector() * Movement * this->NowMoveSpeed * this->DeltaSeconds
);
}

Expand All @@ -472,7 +483,7 @@ void URTSCamera::EdgeScrollDown() const

const auto Movement = UKismetMathLibrary::FClamp(NormalizedMousePosition, 0.0, 1.0);
this->Root->AddRelativeLocation(
-1 * this->Root->GetForwardVector() * Movement * this->EdgeScrollSpeed * this->DeltaSeconds
-1 * this->Root->GetForwardVector() * Movement * this->NowMoveSpeed * this->DeltaSeconds
);
}

Expand Down
2 changes: 1 addition & 1 deletion Source/OpenRTSCamera/Private/RTSSelectable.cpp
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#include "RTSSelectable.h"
#include "RTSSelectable.h"
2 changes: 1 addition & 1 deletion Source/OpenRTSCamera/Public/OpenRTSCamera.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#pragma once

#include "CoreMinimal.h"
#include <CoreMinimal.h>
#include "Modules/ModuleManager.h"

class FOpenRTSCameraModule : public IModuleInterface
Expand Down
17 changes: 8 additions & 9 deletions Source/OpenRTSCamera/Public/RTSCamera.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#pragma once

#include "CoreMinimal.h"
#include <CoreMinimal.h>
#include "InputMappingContext.h"
#include "Camera/CameraComponent.h"
#include "Components/ActorComponent.h"
Expand Down Expand Up @@ -66,7 +66,9 @@ class OPENRTSCAMERA_API URTSCamera : public UActorComponent
float StartingZAngle;

UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "RTSCamera")
float MoveSpeed;
float MaxMoveSpeed;
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "RTSCamera")
float MinMoveSpeed;
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "RTSCamera")
float RotateSpeed;

Expand Down Expand Up @@ -104,13 +106,8 @@ class OPENRTSCAMERA_API URTSCamera : public UActorComponent

UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "RTSCamera - Edge Scroll Settings")
bool EnableEdgeScrolling;
UPROPERTY(
BlueprintReadWrite,
EditAnywhere,
Category = "RTSCamera - Edge Scroll Settings",
meta=(EditCondition="EnableEdgeScrolling")
)
float EdgeScrollSpeed;


UPROPERTY(
BlueprintReadWrite,
EditAnywhere,
Expand Down Expand Up @@ -199,4 +196,6 @@ class OPENRTSCAMERA_API URTSCamera : public UActorComponent
FVector2D DragStartLocation;
UPROPERTY()
TArray<FMoveCameraCommand> MoveCameraCommands;
UPROPERTY()
float NowMoveSpeed;
};
2 changes: 1 addition & 1 deletion Source/OpenRTSCamera/Public/RTSCameraBoundsVolume.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#pragma once

#include "CoreMinimal.h"
#include <CoreMinimal.h>
#include "GameFramework/CameraBlockingVolume.h"
#include "RTSCameraBoundsVolume.generated.h"

Expand Down
3 changes: 1 addition & 2 deletions Source/OpenRTSCamera/Public/RTSHUD.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#pragma once

#include "CoreMinimal.h"
#include <CoreMinimal.h>
#include "GameFramework/HUD.h"
#include "RTSHUD.generated.h"

Expand All @@ -13,7 +13,6 @@ class OPENRTSCAMERA_API ARTSHUD : public AHUD

public:
ARTSHUD();

UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "Selection Box")
FLinearColor SelectionBoxColor;

Expand Down
2 changes: 1 addition & 1 deletion Source/OpenRTSCamera/Public/RTSSelectable.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma once
#pragma once
#include "RTSSelectable.generated.h"

UCLASS(Blueprintable, ClassGroup=(Custom), meta=(BlueprintSpawnableComponent))
Expand Down
2 changes: 1 addition & 1 deletion Source/OpenRTSCamera/Public/RTSSelector.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#pragma once

#include "CoreMinimal.h"
#include <CoreMinimal.h>
#include "InputAction.h"
#include "InputMappingContext.h"
#include "RTSHUD.h"
Expand Down