How do I make a smooth bezier curve

I want to create a throwing system where the item flys from the players hand to the mousepos with a bezier curve but I dont understand how to make it more smooth.

This is a smooth bezier curve:

And this is my attempt on it, but its not smooth as I want it to be. Its choppy

Heres the code I use for the curve:

	for i = 0, 100, 10 do
		local pos = quadraticBezier(partposition ,Height, MousePosition+Vector3.new(0,0.5,0), i/100)
		local tween = TweenService:Create(Part, TweenInfo.new(0.04, Enum.EasingStyle.Linear), {Position = pos})
		tween:Play()
		tween.Completed:Wait()
		
	end
	
	Part.CanCollide = true
	Part.Anchored = false

I’ve tried lerping, its even more choppy than tweening. If you dont need to tween it in a for loop and theres a different solution please tell me.

1 Like

It’s actually a parabola, but that’s not the issue.

Try searching for smooth bullet drop or smooth parabola up in the Search tool.

1 Like

Couple of things,

First, your part loop doesn’t consider how the time could vary between each tween. Even though you specified that the tween be completed in 0.04 seconds, it could complete at some number between 0.039, or 0.041. Maybe in games with other scripts running that hog computation, there’s an even higher chance of your tween.Completed:Wait() completing even later than 0.04. If you do this 100 as per your loop states it, the small errors add up.

Second, I’m assuming you’re controlling the CFrame on the server side with tween. This isn’t recommended as you’ll see stuttering like shown in that video. The better solution would be to animate the apple on the client side, which has control of the player’s rendering frame rate.

With both of those in mind, it can get really complex for just throwing an apple and making it look smooth. Instead of going down that route, the best solution I would recommend is to take advantage of Roblox’s physics system and remove the Bezier curve for the physics handling. You can still use the curve to guide the throw, but the throw itself should be using Roblox’s engine.

apple = appleObject:Clone() -- create an apple object
apple.CFrame = CFrame.new(partPosition) -- move the object to the stating point
apple.AssemblyLinearVelocity = derivativeQuadraticBezier(partPosition, Height, MousePosition + Vector3.new(0,0.5,0)) -- derivative of the bezier position is the velocity at that point
apple.Anchored = false -- part must be unanchored to call setnetworkowner
apple.Parent = workspace -- part must exist before calling set networkowner
apple:SetNetworkOwner(playerWhoThrewApple) -- assign network ownership to the thrower, they will see the apple move smoothly while everyone else will see it stutter.
2 Likes

I don’t understand what
apple.AssemblyLinearVelocity = derivativeQuadraticBezier(partPosition, Height, MousePosition + Vector3.new(0,0.5,0)) means or does.

I’ve looked for explanations, but I don’t understand what they mean. Do I need to apply somekind of force I’m confused.

What Bezier library/module are you using?

for that part I’m referring to the an abstract function that returns the direction vector of that curve at that position.

Also see Egomoose’s tutorial. It implements what I mean a bit better. However, just keep in mind that it doesn’t apply network ownership. Modeling a projectile's motion - Scripting Helpers

You’re doing this on the client right? Tweening on the client is MUCH smoother than tweening on the server.