How to make bullet discharge movement?

Hi :slight_smile:

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 :sweat_smile:

Here’s the attachment that will help positioning the bullet casing (With it’s world position):


image

And that’s the code used:

local Tool = script.Parent
local DischargePoint = Tool.Handle.DischargePoint

local ShootEvent = game.ReplicatedStorage:WaitForChild("ShootRequest")

ShootEvent.OnServerEvent:Connect(function()
	
	local BulletCasing = game.ReplicatedStorage.BulletCasing:Clone()
	BulletCasing.Parent = game.Workspace
	BulletCasing.Position = DischargePoint.WorldPosition
	BulletCasing.Orientation = DischargePoint.WorldOrientation
	
	--Bullet Discharge Code here?
	
	game:GetService("Debris"):AddItem(BulletCasing, 3)
	
end)

And here’s the video to understand more:

Thanks for your time :slight_smile:

set the casing’s velocity using vector3.new

BulletCasing:ApplyAngularImpulse() would be a good choice here!

1 Like

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.

Could you please give me an example code because I don’t really know how to code

yes I know that’s the method but I don’t know how to apply it. If you could provide an example code that may help

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

That looks too complex, I think it can be simpler than that. And as I said earlier, I am not really good at coding so that won’t help me much

Clone your caliber, pivot the model to the ejection position, then apply velocity.

PivotTo(Ejection.CFrame)
local Caliber = Path:Clone()


If it’s easier you could even just clone a cylinder and use position. Gun systems are not an easy thing and I don’t even like making them.