Needing Help with Bezier Curves

(This is also one of my first posts on the devforum, if I am posting wrong please let me know)

Hello, I am currently trying to make a Bezier curve in studio. I have the scripting for the Bezier curve done, however I am currently struggling to make a limiter for how far the player can go with the curve.

For example, I want the player to go only 100 studs with this curve, but if they exceed 120, it will automatically shorten it to 100 studs. How can i do this?

Here is the beginning of my script that has the variables.
function SmackDown(HRP, MouseHit)
local PartThings = script.Parent:WaitForChild(“PartThings”)
local function Curve(t, P0, P1, P2)
local A = P0:Lerp(P1,t)
local B = P1:Lerp(P2,t)
return A:Lerp(B,t)
end

1 Like

Hey there! This belongs in #help-and-feedback:scripting-support, bezier curves are tricky, but think of it as 3 points, starting point, height and then ending point, as seen as here.

these points are then put into a equation and it, usually height isn’t on the curve, unless the curve is flat, aka a line.
image

after the equation it becomes this.
Quadratic-Bezier-Curve-Dynamic-Drawing

These gifs and images are taken directly from Roblox’s official documentation.

Here is a snippet of code

function quadraticBezier(t, p0, p1, p2)
	return (1 - t)^2 * p0 + 2 * (1 - t) * t * p1 + t^2 * p2
end

T is a independent variable, P0 is starting point, P1 is the height, and then P2 is ending point.

Thanks for showing me how to post and handle with bezier curves. Although it doesnt exactly answer my question, I did a little bit more digging and found an answer. Thank you again.

Might be worth posting your answer in case others need it :slight_smile:

You could check the distance from the players character position to p1 (the end position). So if you were to make p1 the mouse.hit position, all you would do is find the distance in magnitude from the character to the mouse position and do a check to see if it’s over 100 studs.