Bullet Eject system

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve?
    I wanted to achieve bullet shell eject system

  2. What is the issue?
    I’ve succeeded with it but the direction it flies to is incorrect
    here’s the demonstration video → Dropbox - Desktop 2023.02.05 - 14.19.54.01.mp4 - Simplify your life

  3. What solutions have you tried so far?
    I’ve tried seeking for help in many different sites such as dev hub, but I didn’t found any useful information for my current problem

Here’s the code

local function eject()
		local shell = game.ReplicatedStorage.MainServer.FX.BulletShells.MP7:Clone()

		shell.Parent = workspace
		local shellPos =  arms.MP7.SlideSmoke.Pos.WorldPosition
		shell.Position = Vector3.new(shellPos.X, shellPos.Y, shellPos.Z)
		shell.CanCollide = true
		shell.Anchored = false
		
		shell.Velocity = (arms.MP7.SlideSmoke.CFrame.rightVector) * .5 + Vector3.new(0,math.random(20, 30),math.random(5,10))
		shell.RotVelocity = Vector3.new(0,math.random(50,300),0)
	end

The issue is that this axis is always in the global y and Z axis.

You will need to try out a CFrame function or peroperty like RightVector or to world space instead.

1 Like

Could you be more specific on how to do that?

you are looking for “VectorToObjectSpace”, you’ll need to access the gun’s cframe to use it, then use the vector you intend as a argument. here’s a example:

local CasingVelocity = Vector3.new(5,0,0)
shell.Velocity = Gun.CFrame:VectorToWorldSpace(CasingVelocity)

you might also want to consider using the Debris service as that’ll delete the bullet casing without having to write a separate script with wait() in it for the bullet casing:

local DebrisService = game:GetService("Debris")
local DeleteTime = 4
DebrisService:AddItem(BulletCasing, DeleteTime)
2 Likes

Thank you! That actually worked :smile:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.