What do you want to achieve? Keep it simple and clear!
Im trying to make the Yellow Sphere go from the GreenBlock to the BlueBlock at a constant speed (The MidPoint is from the script)
What is the issue? Include screenshots / videos if possible!
The issue is that when it gets close to a Block (Green, Blue, Mid) it gets really slow which you can see through the white points i generated below
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
Yes, i have looked for solutions before and i have actually fixed it before but it was for
quadratic bezier curves and the solution for that was to uniform the points so it will go at a constant speed but the problem was that it costed a lot of resources to actually make it go at a constant speed
Hi, no its not the easing mode the problem is that the curve is not uniformed
The Module
function FloatCurves.new(Positions, Speed)
local self = setmetatable({}, FloatCurves)
--// Validation
if not Positions or typeof(Positions) ~= "table" then
return
end
if not Speed or typeof(Speed) ~= "number" then
Speed = 1
end
--// Setup
self.Curve = Instance.new("Vector3Curve")
self.TotalTime = 0
local CurveX, CurveY, CurveZ = self.Curve:X(), self.Curve:Y(), self.Curve:Z()
for i,v in pairs(Positions) do
--// Since the index always starts at 1 we going to check if its bigger than 1
if i > 1 then
--// If it is then we are going to use the magnitude and add it to the curve time to get a more consistent curve speed
local TimeToAdd = (v - Positions[i - 1]).Magnitude / Speed
self.TotalTime += TimeToAdd
end
CurveX:InsertKey(FloatCurveKey.new(self.TotalTime, v.X))
CurveY:InsertKey(FloatCurveKey.new(self.TotalTime, v.Y))
CurveZ:InsertKey(FloatCurveKey.new(self.TotalTime, v.Z))
end
return self
end
function FloatCurves.PositionFromTime(self, CurveTime)
if not CurveTime then
return
end
return Vector3.new(table.unpack(self.Curve:GetValueAtTime(CurveTime)))
end
function FloatCurves.Tween(self, CurveTime, EasingStyle, EasingDirection)
local Alpha = CurveTime / self.TotalTime
local CurveTween = TweenService:GetValue(Alpha, EasingStyle, EasingDirection)
local ActualCurveTime = CurveTween * self.TotalTime
return self:PositionFromTime(ActualCurveTime)
end
LocalScript
local Positions = {
Start.Position,
Middle,
Enemy.Position
}
local Curve = MilkClient.Classes.FloatCurves.new(Positions, 1)
---- Functions ----
local function RenderProjectile(Delta)
local ServerTime = Workspace:GetServerTimeNow()
local CurveTime = (ServerTime) % Curve.TotalTime
Projectile.Position = Curve:PositionFromTime(CurveTime)
end
RunService:BindToRenderStep("ProjectileRender", Enum.RenderPriority.Last.Value, RenderProjectile)
How I would do it is you would get the current bezier point, then get the next bezier point and find their distance, then divide that by how fast you want the projectile to go (This will be your speed). After, tween the projectile to move to the next bezier point with the fixed speed.
yes i know about that “LUT” stuff but im using a Vector3Curve which is a some sort of “Instance” that does curves which im not sure how i will evenly distribute it