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 * Vector3.new(0,10, -10))
local pos2 = character:WaitForChild("HumanoidRootPart").CFrame * (character:WaitForChild("HumanoidRootPart").CFrame.LookVector * 50)
script.Parent.Parent.BezierFire:FireServer(pos0, pos1, pos2, script.Parent)
end
end)`
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)
end
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
end
script.Parent.Parent.BezierFire.OnServerEvent:Connect(function(plr, pos0, pos1, pos2, handle)
local bullet = Instance.new("Part")
bullet.Anchored = true
bullet.CanCollide = false
bullet.Position = pos0
bullet.Parent = workspace
for i = 0,1,1/100 do
wait()
local pos = quadBezier(i,pos0,pos1,pos2)
local p = script.Node:Clone()
p.Position = pos + Vector3.new(0,5,0)
bullet.Position = pos
p.Parent = workspace
end
bullet:Destroy()
end)`
I hope that someone knows more about this, and can help me!