BezierPath, an easy to use and optimized spline path module for TD games and general paths

Also another question, what would be a good way of assigning speed to the thing im trying to move? So currently it calls the module every .1 seconds which will make the movement look all chubby and more like teleporting. Setting the wait to 0 just makes it go super fast… Is there any good way of making it not chubby but also not go in light speed?

1 Like

Well, in my game i use a runservice and workspace:GetServerTimeNow(). You can replace the ServerTimeNow with tick() if you aren’t interesting in client rendering.
In physics theres a super simple formula
Time = Distance / Speed

What i do in my game is the following:
Get the total time it takes to complete the path with the given speed.
local TotalTime = NewPath:GetPathLength() / Speed
Then in the runservice loop i get the T value by just doing
local T = (tick() - StartTime) / (TotalTime)

(StartTime being a stored value of tick() before the looping started)

2 Likes

Hi sorry for bothering you again but I kinda did not get it to work. Thank you for your time in advance

local totalTime = NewPath:GetPathLength() / speed
local startTime = workspace:GetServerTimeNow()

runService.Stepped:Connect(function()
	local t = (tick() - startTime) / (totalTime)
	print(t)
	Part.CFrame = NewPath:CalculateUniformCFrame(t)
end)

that what I did (yes it server based bc I was too lazy to make client rendering rn).
it kinda gets the part stuck -1000000 studs in the void below lol.

This is probably because at first you used workspace:GetServerTimeNow() and then switched to using tick(), I’m pretty sure these functions return completely different numbers

1 Like

that could be, so would I change getServerTimeNow() to tick() ?

1 Like

How did you get it so smooth? For me its either extremely fast or choppy.

The example code i sent does result in choppy movement. In the example video i sent i used run service.
And if you are interested in how i calculated the T value in the run service i just did
local StartTime = tick()
local TotalTime = NewPath:GetPathLength() / Speed
local T = (tick() - StartTime) / (TotalTime)

Wow, thank you for creating such a useful module! I used it in my TD game and the enemy movement is so smooth and clean, here’s what i did using client-side rendering with BezierPath: enemy movement - Roblox

1 Like

Wow, how did you get it so optimized?

It’s actually very simple, to create a new enemy, I make a folder in the enemies folder, storing the spawn time using workspace:GetServerTimeNow() and enemy info (name, speed, hp…), with attributes.

The client then creates the model with ChildAdded, store it in a table and then in a heartbeat, loop through that table to use BezierPath.

If an enemy reaches the end of the path, the server destroys the folder, and then with ChildRemoved remove the enemy from the table and destroy it.

1 Like

Is it also good for performance if you add the enemy right in the for loop to the table? (Also my t value always slightly overshoots causing shadows to flicker once the enemy gets destroyed… How can I fix?)

1 Like

How do u change the speed of the enemys while the enemys are moving without them instantly teleporting ahead?

1 Like

Im pretty sure you can just change the speed variable if its a pre saved one.

yes but i used his rendering method and cant figure out how he changes the enemys speed while the enemy is moving im sure he knows what im talking about

Is it possible to offset smth with that module off some point by set amount, like by 3 studs to bezier start?

I tried that, it kinda worked but also not. They start to walk with the offset but then sometimes just ignore it and it gets to weird results idk

rendering methode? Are you talking about client rendering?

yes? dwjoojdojowdjdwdddwdwdwdddwd

Im pretty sure what he did (I did that also) is to have 2 loops run in parallel. One one the server and one on the client. Just change the speed vars for booth and they will be synced I believe

no lol lemme show u a video of my product

there is odd freezes in this so ill check that out but when i change the speed the enemy just instantly jump which is understandable but my question is how does he change his speed and it not instantly jump to a position