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
Open RTSCam pawn
add springarm and camera
on spring arm, change rotation, arm length, untick Do Collison Test
Go to RTS controller BP, event graph
for WSAD movement:
Collapse function name as MoveCamera for below 4 nodes:
Reorganize the nodes:
(the multiply pin, -1 or +1 determine if WASD movment is opposite or not)
Use event tick to make mouse movement:
if wanna show print string value to test the BP, add the highlight nodes below to test:
Continue the graph (make map move to left when mouse moves to left, camera moves 50 to left )
Continue to make move right too (from break vector 2D node):
promote variable from the make vector and < nodes, name as Camera Scroll Speed and Camera Edge Scroll Threshold (float), drag to 3 places
Add camera scroll speed nodes on keypad BP too:
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:
Final:
Add comment
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):
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:
Then use this to control other scroll speed on Make Vector nodes in this graph:
Use the same delta second concept on keyboard movement graph too:
Now the speed fully controlled by camera scroll speed default value, change to 1000
Zoom Camera:
In project setting, add binding, action mappings:
Back to controller BP graph, add spring arm :
Create inputaction zoomin/out and add variable CameraZoomSpeed:
Collapse highlight nodes above to function, called ZoomCamera
Modify the graph:
Camera Rotation:
by keyboard:
Add new mapping at input:
Make the graph below, test camera rotation speed vairable value from 50 to 200
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:
Go to RTS camera viewport, springarm, rotate x axis 180 degree
by mouse:
Collapse below nodes for function, called RotateCameraLeftRight
Add Axis mapping
Repeat for rotate up and down, duplicate rotatecamer left right function and modify:
To set rotation up and down degree limit (clamp), in rotate camera up down function, modify spring arm:
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:
Back to Controller BP, add spwan actor to classs to in event beingplay:
promote 2 variables for FPS and RTS cam:
Add comment Initization and tick show bubble when zoomed
Add new action mapping:
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)
set graph (check everytime the mode after switching)
To set location that at the same place after switching mode:
Fix FPS camera movement for all inputs (so that can program it alternatively):
In WASD movment by adding branch:
Zoom and rotate camera, do the same:
For event tick (RTS cam with mouse)
Program FPS rotation:
In project setting, axis mapping:
back to event graph:
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):
To create up and down rotation:
go to FPS Camera BP, viewport
Camera component, tick Use pawn control rotation
Program FPS WASD movement: