I am using linear velocity for the first time to make a gun from scratch. I have it so a bullet shoots and goes in the right direction but the further away I want to shoot, the faster it gets and I just want a constant speed. Does anyone know how?
Server Code:
local repliStorage = game:GetService("ReplicatedStorage")
local event = repliStorage.Shoot
event.OnServerEvent:Connect(function(player, target, sp, handle)
local bullet = repliStorage.Bullet:Clone()
bullet.Parent = handle.Parent
bullet.Position = sp
local Attachment = Instance.new("Attachment", bullet)
local LV = Instance.new("LinearVelocity", bullet)
LV.MaxForce = math.huge
LV.VectorVelocity = (target - sp) * 0.5
LV.Attachment0 = Attachment
end)
Client Code:
local handle = script.Parent:WaitForChild("Handle")
local tip = handle:WaitForChild("Tip")
local player = game:GetService("Players").LocalPlayer
local mouse = player:GetMouse()
local repliStorage = game:GetService("ReplicatedStorage")
local db = false
local event = repliStorage.Shoot
mouse.Button1Down:Connect(function()
if db == false then
db = true
local target = mouse.Hit.Position
local tx = target.X
local ty = target.Y
local tz = target.Z
local sp = tip.Position
local spx = sp.X
local spy = sp.Y
local spz = sp.Z
spx = math.floor(spx*100)/100
spy = math.floor(spy*100)/100
spz = math.floor(spz*100)/100
tx = math.floor(tx*100)/100
ty = math.floor(ty*100)/100
tz = math.floor(tz*100)/100
print(spx, spy, spz, "|", tx, ty, tz)
event:FireServer(target, sp, handle, tip)
wait(0.25)
db = false
end
end)