Troop Movement System

Hello, I currently have a movement system for a Unit/Infantry that uses MoveTo() to move it to the position of a province when the player right clicks.

Right now the Unit just moves directly to the clicked province even if that province is 5 provinces away, I need help trying to make a system where the
unit moves to the provinces on the path to the selected one instead of heading straight to it. (Image attatched of what I mean)

So far I have tried using a system where it loops through the provinces and sees which are closest to the chosen one but it wouldn’t work exactly right.

The Server script (shortened so its only the main part shown)

local RS = game:GetService("ReplicatedStorage")
local ChooseNation = RS:WaitForChild("ChooseNation")
local MT = game.Workspace:WaitForChild("MapTesting")

	local UnitHum = Unit:WaitForChild("Humanoid")
	local StartPos = Unit.HumanoidRootPart.Position
	Unit.Values.IsMoving.Value = true
	Unit.Values.IsMoving.Value = false
	Unit.Values.SiegingEnemy.Value = false

A simple solution with your current setup would probably be to just raycast downwards along the path to your selected province. Keep in mind It will definitely have edge cases.

If the raycast hits a province, you’d insert it into some sort of array (Double checking to make sure it doesn’t already exist in the array ofcourse.).

What if the province is much further away and not in a straight line though?

I suppose you could have it bezier curve around things

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.