I’m planning on having a player throw a ball into the air and having it eventually follow a parabolic path, and the path would change based on how much “power” they want to put in. However, I’m struggling to get the ball to move in a parabolic shape.
This is what I have so far. But it doesn’t really work.
local ball = script.Parent
local startPoint = Vector3.new(0, 0, 0)
local targetPoint = Vector3.new(100, 50, 0)
local speed = 10
local function fire(startPoint, targetPoint)
local distance = (targetPoint - startPoint).magnitude
ball.CFrame = CFrame.new(startPoint, targetPoint)
ball.Velocity = ball.CFrame.lookVector * speed
end
fire(startPoint, targetPoint)
And this is what I want the ball’s path to look like.
There are many formulas for a parabola. The standard form of a parabola is y = ax^2 + bx + c (a is the vertical stretch, b is the position of the parabola, and c is the y-intercept), . The vertex form of the parabola is y = a(x-h)^2 + k (a is the vertical stretch, h is the left/right translation, and k is the up/down translation). The factored form is y = a(x - r)(x - s) (a is vertical stretch, (r, s) is the position of the vertex).
Use one of these formulas to get your parabola. I would recommend using factored form. You can get the vertex (or highest point of the ball trajectory, which is based on power) and plug those numbers in to the formula to get your ball trajectory positions.