How to create an RTS game | Unit Movement System [TUTORIAL]

Hey, as a creator of Medieval RTS i decided to post a tutorial about how to make an RTS unit movement system. This system is in no way optimized!

Step 1:
Get the premade unit model from this link to get started: https://www.roblox.com/library/12130875696/Unit
image

  1. Put it in a folder called “Units”

unit.PNG

Step 2:
Create two remote events named “CreateBeam” and “MoveUnit” in ReplicatedStorage
image

Step 3:

Create a script named “UnitMove” in ServerScriptService

image

Then open it and begin writing!

  1. Declare positions as we’ll be using tables to store unit positions.

  2. Then we make the “MoveUnit” remote event function. Add three parameters “player”, “hitpos”, “unit”.

  1. Declare loop to true, it’ll be used to stop the following loop.

  2. Create a table referenced to the unit and put hitpos inside of it.

  3. Fire a client event which will create a beam. Add three parameters “player”, positions[unit][1], “unit”, “false”.

  1. Create a while loop which constantly check whether youve reached the destination or not.

  2. if unit still exists after the loop is done, stop the unit and remove the beam.

  3. This script is done!

Step 4:

Create two local scripts named: “Selection” and “UnitMoveHelper”

image

Then open “Selection” and begin writing.

image

  1. Declare two variables “player” and “Mouse”

  2. Create a function if the Mouse1Button is clicked.

  3. If Mouse.Target doesn’t equal nil then proceed to check if it’s in game.Workspace.Units.

  4. If the unit isn’t selected then select otherwise unselect.

Step 5:

Open the local script that we created earlier named “UnitMoveHelper”

  1. Declare two variables “player” and “Mouse”.

  2. Create a function if the Mouse1Button is clicked.

  3. Once clicked, get all units that are selected and fire a server remote that would move the unit to Mouse.Hit.Position

Step 6:

In the same script as before we make the “CreateBeam” function

  1. If the parameter destroy is false then continue to make a beam, otherwise destroy the beam.

  2. Copy it from below.

OnClientEvent function
game.ReplicatedStorage.CreateBeam.OnClientEvent:Connect(function(hitpos, unit, destroy)
	--// check whether to destroy or create the beam
	if destroy == false then
		if unit.Parent then
			if not unit.PrimaryPart:FindFirstChild("Beam") then

				--// create an attachment
				local attachment = Instance.new("Attachment")
				attachment.WorldPosition = hitpos
				attachment.Name = "AttBeam"
				attachment.Parent = unit.Ignore

				--// create a beam
				local beam = Instance.new("Beam")
				beam.Color = ColorSequence.new(Color3.fromRGB(255, 255, 255),Color3.fromRGB(255, 144, 146))
				beam.Width0 = 0.2
				beam.Width1 = 0.2
				beam.FaceCamera = true
				beam.Attachment0 = unit.PrimaryPart.Att
				beam.Attachment1 = attachment
				beam.Parent = unit.PrimaryPart
			else
				--// if there's already a beam:
				local attachment = Instance.new("Attachment")
				attachment.WorldPosition = hitpos
				attachment.Name = "AttBeam"
				attachment.Parent = unit.Ignore
				
				unit.PrimaryPart:FindFirstChild("Beam").Attachment0 = unit.PrimaryPart.Att
				unit.PrimaryPart:FindFirstChild("Beam").Attachment1 = attachment
			end
		end
	else
		--// destroy beam and attachment 
		if unit.PrimaryPart:FindFirstChild("Beam") then
			unit.PrimaryPart:FindFirstChild("Beam"):Destroy()
		end
		for i,v in pairs(unit.Ignore:GetChildren()) do
			if v.Name == "AttBeam" then
				v:Destroy()
			end
		end
	end
end)

Experiencing Issues?

image

  1. Launch the game with the Output bar and look for errors.

  2. If you have questions then reply to this topic.

Final Result:

RobloxStudioBeta_xJmI1VJ5k4

You must polish the scripts provided above, as they’re not supposed to be final.

123 Likes

Cool man! Thank god I found this I wanted to make a RTS game but there any good tutorials.
Hopefully u can keep making posts on this tutorial!

16 Likes

Awesome, this is really great. Hopefully we get some more :laughing: :slight_smile:

4 Likes

This is awesome dude! I hope you canake a tutorial on how to make a unit training system! Either way, awesome tutorial!

5 Likes

Thanks, I probably won’t make another tutorial unfortunately…

3 Likes

If I may ask, What do you mean by script before?

3 Likes

I mean that you should write the code in the same script

4 Likes

Could you make an updated tutorial covering most aspects of an RTS game and its functionalities?

There are little to no resources on RTS systems and how they work, it would be a great help to the community if you could!

5 Likes

Please do more these tutorials help me learn and create a game at the same time!

3 Likes

This is super dude thank you. İm learning unut movement

2 Likes

Nice tutorial, but it’s good to show how to make angle calculation, you can use cframe.lookat():toorientation() it’s very usefull to get 3 axis, if you wan’t world space then add :toworldspace before toorientation

2 Likes

Yes, this method I’ve shown is just for educational purposes because it’s rushed.

3 Likes

good tutorial! I would like you to make more such tutorials

1 Like

yea, i love rts games, and i wanted to make one, but i’m too lazy xd,but anyways, make more tutorials like this, because old players of roblox don’t much like clickers as i know, soo this games are engaging, i worked with vectors soo remotes ect. is kind of meh for me , but maybe one day i’ll make game.

2 Likes

and one thing more, why you made soo complicated movement, you can use humanoid, i know it’s laggy, or use simply tweens, or body velocity and gyro - this will be the best option, for example TC3 have this like movement as i know, because it have collisions and it’s easy to make, moreover you making one big mistake, if position = position, this don’t works everytime, especially when you have multiple units and positions can be … soo better is to detect near magnitude like 0.1, it’s always safe, i used body gyro and velocity to make animals for game, and this worked, collision groups can be helpfull with this, and i know this can be messy and anchored parts are better.

2 Likes

That’s what I do in my game already. This tutorial is not meant to give players a fully working script.

4 Likes

yea, but use gyro and position for your game xd

2 Likes

How is gyro better than velocity? gyro is deprecated.

3 Likes

it’s maybe deprecated, but it works, and body velocity is deprecated too, i know using deprecated things are bad blah blah blah, but many games using it, body gyro is the best for that, align orientation aren’t as good as it, soo you can use it, and it’s don’t broken if you know how to use it, i used it to rotate player in weapon system (third person system) and it’s the easiest and the best. Old things sometimes is the best

2 Likes

I think velocity works fine, but playing Medieval RTS i kinda noticed that when there’s a lot of units moving in the map, the movement system starts lagging which makes the units move slower, I don’t know if this problem is caused by the linear velocity, but it could be.

2 Likes