Add RTS camera Panning

Top-Down cam, & switch from/to 1st pesron



Delete the starter in scene in Top Down project
Create a folder called RTS
add RTSCamera Pawn and TRS Controller BP
Change the project setting
image.png

Open RTSCam pawn
add springarm and camera
on spring arm, change rotation, arm length, untick Do Collison Test
image.png

Go to RTS controller BP, event graph

for WSAD movement:

image.png
Collapse function name as MoveCamera for below 4 nodes:
image.png
Reorganize the nodes:
image.png
(the multiply pin, -1 or +1 determine if WASD movment is opposite or not)

Use event tick to make mouse movement:

image.png
if wanna show print string value to test the BP, add the highlight nodes below to test:
image.png
Continue the graph (make map move to left when mouse moves to left, camera moves 50 to left )
image.png
Continue to make move right too (from break vector 2D node):
image.png
promote variable from the make vector and < nodes, name as Camera Scroll Speed and Camera Edge Scroll Threshold (float), drag to 3 places
image.png
Add camera scroll speed nodes on keypad BP too:
image.png
Now change Camera speed default value can change the moving speed

Do the up and down movement as well:

Add a sequence here and extend the nodes on 1:
image.png
Final:
image.png
Add comment
image.png

Frame Independence (to make constant movement speed):


In Cmd column in main menu, type: stat fps to show current fps value
If lower fps to 30, type t.MaxFPS 30 (so the camera move slower, i.e. faster computer move faster, and vice versa. We want constant speed regardless of computer speed)

Go to project setting, Engine, general setting, tick fixed frame rate (this way change fps permanently, type on cmd only change temporarily, until UE restarts):
image.png

to control frame independence, depends on delta seconds on event tick node (which gives duration the last frame took):
Open RTS Controller BP, add multiply and camera scroll speed nodes, set camera default scroll speed to 25:
image.png
Then use this to control other scroll speed on Make Vector nodes in this graph:
image.png
Use the same delta second concept on keyboard movement graph too:
image.png

Now the speed fully controlled by camera scroll speed default value, change to 1000


Zoom Camera:


In project setting, add binding, action mappings:
image.png
Back to controller BP graph, add spring arm :
image.png
Create inputaction zoomin/out and add variable CameraZoomSpeed:
image.png
Collapse highlight nodes above to function, called ZoomCamera
Modify the graph:
image.png

Camera Rotation:


by keyboard:
Add new mapping at input:
image.png
Make the graph below, test camera rotation speed vairable value from 50 to 200
image.png

Now it can rotate but only on fixed world axis, not along local axis. I.e. will move to different direction if rotate to different angle.
To fix this:
Open Move Camera function, add follow nodes:
image.png
Go to RTS camera viewport, springarm, rotate x axis 180 degree
image.png

by mouse:
Collapse below nodes for function, called RotateCameraLeftRight
image.png
Add Axis mapping
image.png
image.png
Repeat for rotate up and down, duplicate rotatecamer left right function and modify:
image.png
image.png

To set rotation up and down degree limit (clamp), in rotate camera up down function, modify spring arm:
image.png

Switch between FPS and RTS camera:


Create new BP character in RTS folder, name as FPSCamera
Add camera component in viewport, location x as 60:
image.png
Back to Controller BP, add spwan actor to classs to in event beingplay:
image.png
promote 2 variables for FPS and RTS cam:
image.png
Add comment Initization and tick show bubble when zoomed
image.png

Add new action mapping:
image.png
back to controller, add variable boolean (if it’s true, in RTS, if it’s false, in FPS), tick default value as true (will start as RTS mode)
image.png
set graph (check everytime the mode after switching)
image.png

To set location that at the same place after switching mode:
image.png

Fix FPS camera movement for all inputs (so that can program it alternatively):

In WASD movment by adding branch:
image.png
Zoom and rotate camera, do the same:
image.png
For event tick (RTS cam with mouse)
image.png

Program FPS rotation:

In project setting, axis mapping:
image.png
back to event graph:
image.png
Go to Switching FPD and RTS mode graph, extend follow
(to let rotation without holding R click, but I don’t need the followig nodes, still rotate without holding R click):
image.png

To create up and down rotation:

go to FPS Camera BP, viewport
Camera component, tick Use pawn control rotation
image.png

Program FPS WASD movement:

Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
CtrlP
) instead.