@@ -26,7 +26,9 @@ URTSCamera::URTSCamera()
2626 this ->FindGroundTraceLength = 100000 ;
2727 this ->MaximumZoomLength = 5000 ;
2828 this ->MinimumZoomLength = 500 ;
29- this ->MoveSpeed = 50 ;
29+ this ->MaxMoveSpeed = 1024 .0f ;
30+ this ->MinMoveSpeed = 128 .0f ;
31+ this ->NowMoveSpeed = this ->MinMoveSpeed ;
3032 this ->RotateSpeed = 45 ;
3133 this ->StartingYAngle = -45 .0f ;
3234 this ->StartingZAngle = 0 ;
@@ -114,6 +116,12 @@ void URTSCamera::OnZoomCamera(const FInputActionValue& Value)
114116 this ->MinimumZoomLength ,
115117 this ->MaximumZoomLength
116118 );
119+
120+ // Calculate Alpha for Lerp (0 at min zoom, 1 at max zoom)
121+ float Alpha = (this ->DesiredZoomLength - this ->MinimumZoomLength ) / (this ->MaximumZoomLength - this ->MinimumZoomLength );
122+
123+ // Lerp NowMoveSpeed between MinMoveSpeed and MaxMoveSpeed
124+ this ->NowMoveSpeed = FMath::Lerp (this ->MinMoveSpeed , this ->MaxMoveSpeed , Alpha);
117125}
118126
119127void URTSCamera::OnRotateCamera (const FInputActionValue& Value)
@@ -228,7 +236,7 @@ void URTSCamera::ApplyMoveCameraCommands()
228236 {
229237 auto Movement = FVector2D (X, Y);
230238 Movement.Normalize ();
231- Movement *= this ->MoveSpeed * Scale * this ->DeltaSeconds ;
239+ Movement *= this ->NowMoveSpeed * Scale * this ->DeltaSeconds ;
232240 this ->Root ->SetWorldLocation (
233241 this ->Root ->GetComponentLocation () + FVector (Movement.X , Movement.Y , 0 .0f )
234242 );
@@ -424,7 +432,7 @@ void URTSCamera::EdgeScrollLeft() const
424432 const auto Movement = UKismetMathLibrary::FClamp (NormalizedMousePosition, 0.0 , 1.0 );
425433
426434 this ->Root ->AddRelativeLocation (
427- -1 * this ->Root ->GetRightVector () * Movement * this ->EdgeScrollSpeed * this ->DeltaSeconds
435+ -1 * this ->Root ->GetRightVector () * Movement * this ->NowMoveSpeed * this ->DeltaSeconds
428436 );
429437}
430438
@@ -440,7 +448,7 @@ void URTSCamera::EdgeScrollRight() const
440448
441449 const auto Movement = UKismetMathLibrary::FClamp (NormalizedMousePosition, 0.0 , 1.0 );
442450 this ->Root ->AddRelativeLocation (
443- this ->Root ->GetRightVector () * Movement * this ->EdgeScrollSpeed * this ->DeltaSeconds
451+ this ->Root ->GetRightVector () * Movement * this ->NowMoveSpeed * this ->DeltaSeconds
444452 );
445453}
446454
@@ -456,7 +464,7 @@ void URTSCamera::EdgeScrollUp() const
456464
457465 const auto Movement = 1 - UKismetMathLibrary::FClamp (NormalizedMousePosition, 0.0 , 1.0 );
458466 this ->Root ->AddRelativeLocation (
459- this ->Root ->GetForwardVector () * Movement * this ->EdgeScrollSpeed * this ->DeltaSeconds
467+ this ->Root ->GetForwardVector () * Movement * this ->NowMoveSpeed * this ->DeltaSeconds
460468 );
461469}
462470
@@ -472,7 +480,7 @@ void URTSCamera::EdgeScrollDown() const
472480
473481 const auto Movement = UKismetMathLibrary::FClamp (NormalizedMousePosition, 0.0 , 1.0 );
474482 this ->Root ->AddRelativeLocation (
475- -1 * this ->Root ->GetForwardVector () * Movement * this ->EdgeScrollSpeed * this ->DeltaSeconds
483+ -1 * this ->Root ->GetForwardVector () * Movement * this ->NowMoveSpeed * this ->DeltaSeconds
476484 );
477485}
478486
0 commit comments