I am trying to make a gun with realistic features and I am willing to add bullet discharge or whatever it’s called (it’s when the bullet casing discharges from the gun). I was able to clone the bullet casing and position it to the discharging place but I just need the code to allow me animate it’s exit. In other words, I want to know how to make it move away from the gun. hope you understand me because my English is bad
Here’s the attachment that will help positioning the bullet casing (With it’s world position):
when I do bullet ejection I apply a sligtly random velocity while pivoting bullet to the eject position (welded to gun like aim part but eject part) and I apply the lookvector of it.
so first have a part in your gun and make it face the direction and put it where you want ur bullet to eject.
the kinda hard part is coding it but here’s an example. I can’t help that much right now so I’ll just give you this
local caliber:Model = GetInstance("Caliber", "Model")
if caliber then
caliber = caliber:Clone()
caliber:PivotTo(GetPart("Ejection").CFrame)
caliber.PrimaryPart.CanCollide = true
for _,v in caliber:GetDescendants() do
if v:IsA("BasePart") then
for _,e in Parent.Parent:GetDescendants() do
if e:IsA("BasePart") then
local n = Instance.new("NoCollisionConstraint")
n.Part0 = v
n.Part1 = e
n.Parent = v
end
end
end
end
caliber.PrimaryPart.Massless = false
caliber.PrimaryPart.CustomPhysicalProperties = PhysicalProperties.new(.1, 2, .2, 100, 100)
caliber.Parent = workspace
caliber.PrimaryPart.AssemblyLinearVelocity = GetPart("Ejection").CFrame.LookVector*20
local function r()
return math.random(-15,15)
end
caliber.PrimaryPart.AssemblyAngularVelocity = Vector3.new(r(), r(), r())
end