I’ve recently been wanting to practice my scripting skills by making a gun with recoil, bullet drop, velocity etc. But one thing I am stuck on is what the best way to complete this. I’ve gotten as far as the actual functions and reload, but the bullet properties is what I am stuck on. All I’m asking for is links to material that I could not find or a snippet of a proper gun.
My raycasting and bullet creation
local origin = script.Parent.Handle.End.Position
local direction = (Position - origin).Unit
local RayParams = RaycastParams.new()
RayParams.IgnoreWater = true
--print(Target.Name)
local RayResult = workspace:Raycast(Position, direction, RayParams)
local intersection = RayResult and RayResult.Position or origin + direction * 300
local distance = (origin - intersection).Magnitude
local bullet_clone = Instance.new("Part")
bullet_clone.Name = "Bullet"
bullet_clone.Size = Vector3.new(.08, .08, .08)
bullet_clone.CFrame = CFrame.new(origin, intersection)
bullet_clone.Anchored = false
bullet_clone.Parent = workspace
local BodyVelocity = Instance.new("BodyVelocity")
BodyVelocity.velocity = bullet_clone.CFrame.LookVector * Velocity
--print(bullet_clone.CFrame.LookVector)
BodyVelocity.Parent = bullet_clone
wait(intersection/Velocity)
bullet_clone:Destroy()
local BulletHole = game.ReplicatedStorage.BulletHole
local BulletHoleCopy = BulletHole:Clone()
BulletHoleCopy.Position = Position
BulletHoleCopy.Anchored = true
if Target.Name == "Left" or Target.Name == "Right" then
BulletHoleCopy.Orientation = Vector3.new(0, 90, 0)
end
if Target.Name == "Front" or Target.Name == "Back" then
BulletHoleCopy.Orientation = Vector3.new(0, 0, 0)
end
if Target.Name == "Top" or Target.Name == "Bottom" then
BulletHoleCopy.Orientation = Vector3.new(90, 0, 0)
end
BulletHoleCopy.Parent = workspace
wait(2)
BulletHoleCopy:Destroy()
if RayResult then
print("yes")
end