So I am making a client-sided entity system and I used SimpleSpline for the movement, this model is good since I can detect when it reaches a node, The only problem is when I test the game with 0 tension they go off the path and not straight, the best solution I have is making it 0.7, but the turning looks too fast, Any solutions or should I get a new catrom model?
Client Script:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
local Instances = ReplicatedStorage:WaitForChild("Enemies")
local NodesFolder = game.Workspace:WaitForChild("Waypoints")
local spline = require(ReplicatedStorage.Modules:WaitForChild("SimpleSpline"))
local enemyInfo = require(ReplicatedStorage.Modules:WaitForChild("mobInfoModule"))
ReplicatedStorage:WaitForChild("Events"):WaitForChild("SendInfo").OnClientEvent:Connect(function(name, id)
if Instances:FindFirstChild(name) then
local entityClone = Instances:FindFirstChild(name):Clone()
entityClone.Parent = workspace.Enemies.Active
entityClone.Name = name
if entityClone:IsA("Model") then
local primaryPart = entityClone.PrimaryPart
entityClone.PrimaryPart.CFrame = NodesFolder[1].CFrame
if primaryPart then
for i,v in pairs(entityClone:GetChildren()) do
if v:IsA("BasePart") or v:IsA("MeshPart") then
v.CollisionGroup = "Enemy"
end
end
coroutine.wrap(moveEntity)(entityClone, enemyInfo[name].Speed)
task.wait(0.025)
else
warn("Entity clone does not have a PrimaryPart: " .. entityClone.Name)
end
else
warn("Invalid entity clone type: " .. entityClone.ClassName)
end
end
end)
local Points = {}
local nodeNames = {}
for _, node in ipairs(NodesFolder:GetChildren()) do
local nodeName = tonumber(node.Name)
if nodeName then
table.insert(nodeNames, nodeName)
end
end
table.sort(nodeNames)
for _, nodeName in ipairs(nodeNames) do
local node = NodesFolder:FindFirstChild(tostring(nodeName))
if node then
table.insert(Points, node.CFrame)
end
end
local catRom = spline.new(Points, 0, 0.7)
catRom:Visualize()
catRom:SetOptions({
Uniform = true,
Offset = CFrame.new(0,1,0),
Loop = false,
Reverse = false
})
function moveEntity(obj, speed)
-- * CFrame.new(Vector3.new(Random.new():NextInteger(-1, 1), 1.5, 0)))
local AnimationTrack = obj.AnimationController.Animator:LoadAnimation(obj.Walk)
AnimationTrack:Play()
local startTime = workspace:GetServerTimeNow()
local startCFrame = obj.PrimaryPart.CFrame
local Distance = (Points[#Points].Position - startCFrame.Position).Magnitude
local duration = Distance / speed
local path = catRom:FollowPath(obj, catRom:GetSpeedFromTime(Distance/speed))
path.Completed:Connect(function()
obj:Destroy()
end)
end