7.Multiplayer Setup & player starting camp

11.Resource (gold mining) Collection



Create Golden Mineral Nodes


Create a BP actor, called ResourceNode
Make follow mesh
untick affect navigation
image.png
image.png

Open TopDown Map level, place the resource nodes and relocate the PlayerStartCamp units at 4 corners closer to each other
image.png

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
image.png
Change capsule size to 20,20, move the cube inside the capsule
image.png
Child a new static mesh under Body, called Nose
image.png
And then another mesh, called Spinner
image.png

To make the spinner rotate on the top of truck:
image.png

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:
image.png

To apply the team color for new meshes:


Go to Parent Unit Class, add variables:
image.png
Replace Mesh variable before Setup Team color command:
image.png
delete the mesh nodes

Open Unit Style 1, construction script:
image.png
Repeat the same on Unit Style 2

In Resource Truck, construciton script,
duplicate the ADD node, and connect with Nose, Spinner components as such:
image.png
Test it

To fix the movement of Trucks not too jerky:


Open Parent unit class, select the root in component, untick Rotation Yaw
image.png
Go to Character movement component, tick use controller desired rotation
image.png

Mining the mineral nodes


Create a new BP interface called RTS Resource Interface
Add functions as:
image.png
For set is working, add input:
image.png

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)
image.png
Now the set is working needs to call the server by new custom event:
Replicates: Run on server
image.png
image.png
Make the new graph by disconnect Set is not working node that made before:
image.png
*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:
image.png
Make variables for event set is working node:
image.png
Graph as (in == node, drag out and typed get team number to get such node
image.png
Continue, add a float variable, closest drop off building distance, default value as 5000:
image.png

if for each loop is completed after find nearest dropoff point, will move to next target:
Add another boolean variable, hasReource?
image.png
Overall:
image.png

To create overlapping interaction of the trucks (23:30):


Add box collision child under capsule component, called Resource overlapper, location in front of truck
image.png

Open Resource node BP, event graph,
add RTS resource interface and set follow graph:
image.png

Back to Resrouce Truck graph, create event collect node:
image.png
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)
image.png
Go to Resource node, static mesh component, choose No on character step up on:
image.png
Go to Parent Building class, create overlap event:
image.png
Back to Resource Truck BP, add event dropoff:
image.png
Also setup Event Set not working node:
image.png
Also add following 3 nodes in Event collect:
image.png

Add particle system and audio (multicast) in trucks:


In Resource Truck BP, add Particle system, change its template to P_Spark:
image.png
image.png
and audio, set details as:
image.png
In viewport, scale down the system to 0.2, put it infront of the truck,
untick Auto activate on both particle and audio components
image.png
In event graph, add custom events (multicast) at the following 4 cases:
1 - After stop movement command, make replicate as multicast:
image.png
Graph as:
image.png
2. To stop the multicast effect (particle system and audio) after picked up the resource:
image.png
To change body material after multicast done:
image.png
3. For multicast dropoff:
image.png
4. For multicast not working:
image.png

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
image.png
Add follow nodes from for each loop:
image.png
Add custom event, Server Pass thru set Not Working,
replicates Run on server, add input
image.png
connect as:
image.png
highlight the following, collapse to macro as HandleRightClickToMoveUnit
image.png
Final
image.png


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
image.png
Go to RTS interface, add function:
image.png
Go to Player controller, make a integer variable, set replicated
image.png
Open Get Result Amount interface and set as:
image.png
Back to the widget, set binding on text on resource amount text layer:
image.png
image.png

For increment amount in player controller:


Go to RTS interface, add
image.png
To player controller, event graph
image.png
Go to Resource Truck BP, event dropoff node, add follow:
image.png

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.