Need help with applying math into a script

Hello,

So I got a formula which will make a parabola. This is the formula y = -0.03x² + 0.4x + -0.1 now I don’t really know how to apply it into a script so the script will make the parabola with spheres, so if someone could show me how to do that that would be great.

If you’re interested what that formula will make it will make this:

just to clarify do you want a sphere part to track the parabola?
if so i made a mini part with a trail and script already made so you can mess around it only moves on the x and z axis so you can get a birds eye view on it
quadratic ball move.rbxm (4.5 KB)

If this is going to be along one of the world axes then that would be easy, but as @bigploom said, we need more context of what you are trying to accomplish:
Will the spheres be moving along the line?
Is this line going to be along a stationary y graph axis, or will it rotate around in the world directions like a player throwing a ball or shooting an arrow?

1 Like

Exactly what u said: “to throw a ball”. So basically the direction the player is aiming at it will calculate a line which is the parabola and then the ball should move along with it.

You can get the y value of the parabola using a function:

local function parabola(x)
    return -0.03 * x ^ 2 + 0.4 * x + -0.1
end

If you want to create the parabola with spheres, you can iterate through the points using a for loop:

for x = 1, 10 do --> For every stud from 1 to 10 a sphere will generate in the corresponding position
    local Sphere = --> the sphere
    Sphere.Position = Vector3.new(x, parabola(x), 0)
end

image

2 Likes

Thank you this was exactly what I needed! One last thing though, how would I make it that the ball will follow the calculated path and make it go faster with a integer so you can change the speed whenever you want? @TOP_Crundee123

@VegetationBush
I’m using this script

local rep = game:GetService("ReplicatedStorage")
local event = rep:WaitForChild("CheckLine").CheckEvent



event.OnServerEvent:Connect(function(player, cframe)
	local ball = player.Backpack:FindFirstChild("DodgeBall") or player.Character:FindFirstChild("DodgeBall")
	print(ball)
	
	
	local handle = ball.Handle:Clone()
	handle.Parent = game.Workspace
	handle.Anchored = false
	handle.Name = "DodgeBall"
	handle.CanCollide = true
	print("worked")
	
	
	
	local rayOrigin = player.Character.HumanoidRootPart.Position
	local rayDirection = Vector3.new(0, -100, 0)
	
	local raycastParams = RaycastParams.new()
	raycastParams.FilterDescendantsInstances = {player.Character.HumanoidRootPart.Parent}
	raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
	local raycastResult = workspace:Raycast(rayOrigin, rayDirection, raycastParams)
	
	
	print("very noice")
	ball:Destroy()
	
	local shotSpeed = 100
	
	
	
	
	local function paraBola(x)
		print(-0.03 * x ^ 2 + 0.04 * x + 5)
		return -0.03 * x ^ 2 + 0.04 * x + 5
		
	end
	
	for x = player.Character.HumanoidRootPart.Position.X, raycastResult.Instance.Position.X, 1/100 do
		print("for loop works so everything must work")
		local sphere = Instance.new("Part", workspace)
		sphere.Shape = "Ball"
		sphere.Name = "ParabolaPart"
		sphere.Size = Vector3.new(1,1,1)
		sphere.Position = Vector3.new(x, paraBola(x), 1)
		sphere.Anchored = true

	end
	
	
	
	
end)

But there are some problems with it cause I want it to make the startingpoint the HumanoidRootPart and the endpoint the position where the raycast got hit. Now it does create a parabole well kind of though… But not from the HumanoidRootPart to the raycastResult position.

Please help me with this!

If you want to throw it faster just increase the rate at which x increases.

I’m not sure how to get it from the throwing position to the target though.