Need help with CFrame

Hi there!

I’ve come to this stage where i know the basics and more advanced stuff of scripting. I wanna learn new things, so i started trying bezier curves. I understand the formula, and i wanted to make a simple gun with it. However, i don’t know really much about CFrame math. My friend helped me a bit but we couldnt find the right values.

I’m using this script on the client:

`local uis = game:GetService(“UserInputService”)
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()

uis.InputBegan:Connect(function(input, s)
if s then return end

if input.UserInputType == Enum.UserInputType.MouseButton1 then
	local handleC = script.Parent.CFrame
	local pos0 = handleC.Position
	local pos1 = character:WaitForChild("HumanoidRootPart").CFrame * (character:WaitForChild("HumanoidRootPart").CFrame.UpVector *,10, -10))
	local pos2 = character:WaitForChild("HumanoidRootPart").CFrame * (character:WaitForChild("HumanoidRootPart").CFrame.LookVector * 50)

	script.Parent.Parent.BezierFire:FireServer(pos0, pos1, pos2, script.Parent)

I’m not using position for this, because if i did, the direction wouldnt match the orientation of the character.

Here’s the server script:

function lerp(a, b, c)
return a * ((b - a) * c)

function quadBezier(t, p0, p1, p2)
local L1 = lerp(p0, p1, t)
local L2 = lerp(p1, p2, t)
local quad = lerp(L1, L2, t)
return quad

script.Parent.Parent.BezierFire.OnServerEvent:Connect(function(plr, pos0, pos1, pos2, handle)
	local bullet ="Part")
	bullet.Anchored = true
	bullet.CanCollide = false
	bullet.Position = pos0
bullet.Parent = workspace

for i = 0,1,1/100 do
	local pos = quadBezier(i,pos0,pos1,pos2)
	local p = script.Node:Clone()
	p.Position = pos +,5,0)
	bullet.Position = pos
	p.Parent = workspace

I hope that someone knows more about this, and can help me!

1 Like

It’s good that you’re trying different things, but I’m confused as to why you’d want a bezier trajectory and especially create control points that go toward the player, then forward? Besides this wouldn’t look nice either if you’re moving your character.

The problem is your lerp function, it should be:

function lerp(p0, p1, t)
    return (1 - t) * p0 + t * p1

And if you want to CFrame the interpolation:
local cf =, pos2)
Then make the bullet CFrame equal to cf.

1 Like

Thanks! Yeah, it’s a bit confusing, as i said i’m learning and i wasn’t completely sure what i was doing. This helped a lot, thanks again!

1 Like