Create Golden Mineral Nodes
Create a BP actor, called ResourceNode
Make follow mesh
untick affect navigation
Open TopDown Map level, place the resource nodes and relocate the PlayerStartCamp units at 4 corners closer to each other
Create a Resource Truck
Create child BP from Parent unit class, rename as ResourceTruck
Add static mesh component, name as Body, use a shape cube as mesh, scale down to 0.2
Change capsule size to 20,20, move the cube inside the capsule
Child a new static mesh under Body, called Nose
And then another mesh, called Spinner
To make the spinner rotate on the top of truck:
To change the units mesh in the game:
Go back to main menu level,
Open player controller, Spawn Players Starting Loadout:
change Class in spawn actor unit style 1:
To apply the team color for new meshes:
Go to Parent Unit Class, add variables:
Replace Mesh variable before Setup Team color command:
delete the mesh nodes
Open Unit Style 1, construction script:
Repeat the same on Unit Style 2
In Resource Truck, construciton script,
duplicate the ADD node, and connect with Nose, Spinner components as such:
Test it
To fix the movement of Trucks not too jerky:
Open Parent unit class, select the root in component, untick Rotation Yaw
Go to Character movement component, tick use controller desired rotation
Mining the mineral nodes
Create a new BP interface called RTS Resource Interface
Add functions as:
For set is working, add input:
Implement Right click to collect resource on resource nodes:
Go to Player Controller, event graph,
Right mouse button node, start from break it result node, hit actor:
(units in grab selected units node should connect to array in for each loop node)
Now the set is working needs to call the server by new custom event:
Replicates: Run on server
Make the new graph by disconnect Set is not working node that made before:
*for each loop node may have to re-do, to connect target input on server pass thru set is working node
Go to Resource truck, event graph
Add RTS rerouse interface in class setting:
Make variables for event set is working node:
Graph as (in == node, drag out and typed get team number to get such node
Continue, add a float variable, closest drop off building distance, default value as 5000:
if for each loop is completed after find nearest dropoff point, will move to next target:
Add another boolean variable, hasReource?
Overall:
To create overlapping interaction of the trucks (23:30):
Add box collision child under capsule component, called Resource overlapper, location in front of truck
Open Resource node BP, event graph,
add RTS resource interface and set follow graph:
Back to Resrouce Truck graph, create event collect node:
Continue by promote variable on set timer by event node, called Resource collect timer:
(let the unit interact the gold resource node and stay for 4 sec, then hit back to the first building)
Go to Resource node, static mesh component, choose No on character step up on:
Go to Parent Building class, create overlap event:
Back to Resource Truck BP, add event dropoff:
Also setup Event Set not working node:
Also add following 3 nodes in Event collect:
Add particle system and audio (multicast) in trucks:
In Resource Truck BP, add Particle system, change its template to P_Spark:
and audio, set details as:
In viewport, scale down the system to 0.2, put it infront of the truck,
untick Auto activate on both particle and audio components
In event graph, add custom events (multicast) at the following 4 cases:
1 - After stop movement command, make replicate as multicast:
Graph as:
2. To stop the multicast effect (particle system and audio) after picked up the resource:
To change body material after multicast done:
3. For multicast dropoff:
4. For multicast not working:
To set what happen when event set not working:
Go to Player Controller, right mouse button node:
collapse follow nodes to marcos, called handle Handle Right Click Resource Node
Add follow nodes from for each loop:
Add custom event, Server Pass thru set Not Working,
replicates Run on server, add input
connect as:
highlight the following, collapse to macro as HandleRightClickToMoveUnit
Final
Create a widget and variable to track number of resource be collected:
Rename Selected Unit Area widget (created before) as Main UI Widget
Add 2 text layers, set variable on resource amount text
Go to RTS interface, add function:
Go to Player controller, make a integer variable, set replicated
Open Get Result Amount interface and set as:
Back to the widget, set binding on text on resource amount text layer:
For increment amount in player controller:
Go to RTS interface, add
To player controller, event graph
Go to Resource Truck BP, event dropoff node, add follow: