EDIT: I have figured out how to do it. I moved my invisible part up to compensate for the bullet drop and multiplied the CFrame (with only it's rotation by subtracting the Vector3 value of the CFrame from the whole CFrame) by the front face using Vector3.fromNormalId so the direction would be the face that's pointing to the right of the gun. The script is below:
local bullet = b:Clone()
bullet.Parent = workspace
bullet.CFrame = CFrame.new(Tool.Eject.Position,workspace.CurrentCamera.CoordinateFrame.p)
local direction = (Tool.Eject.CFrame - Tool.Eject.CFrame.p) * Vector3.FromNormalId(Enum.NormalId.Front)
bullet.Velocity = direction * 10
game.Debris:AddItem(bullet,1)
Apologies for the vague title, I was not too sure how to word it.
Hi guys, I have a gun with all the parts inside of the gun welded to each other. I'm trying to make bullet shells eject from an invisible part on my gun. My current snippet of code so far for my shell ejection is this:
local bullet = b:Clone() --b is a variable I made earlier on in the full script that references a part.
bullet.Parent = workspace
bullet.CFrame = CFrame.new(Tool.Eject.Position,workspace.CurrentCamera.CoordinateFrame.p) --The shells come from the Eject part in the tool.
bullet.Velocity = Vector3.new(10,5,0) * bullet:GetMass() * 192.6 --Using this to propel the bullet shells to the right of the gun and up in the air without it dropping too fast.
bullet.BodyAngularVelocity.angularvelocity = Vector3.new(math.random(),math.random(),math.random()) --Trying to make the bullet spin around randomly in the air, working on this later.
game.Debris:AddItem(bullet,1)
The velocity works fine and dandy when I'm facing straight ahead where I spawn. However, if I move my camera around (I'm in first person by the way and I have used code to make my neck move in relation to my mouse, welding my arms to the head and offsetting them appropriately), the velocity of the bullet shells go where I don't want it to go.
For example: If I turned my character horizontally 90 degrees to the left, the bullet shells would fly to the back of the gun. Another 90 degrees and the bullet shells would fly to the left - and so on. If I moved my camera down to make my gun face the floor, the shells would fly way too high - and vice versa.
I was wondering how I could set the velocity of the bullet shells in relation to another part's position, for example, my eject part, so that the shells of my gun always fly out of the right side of the eject part of my gun.
Again, I apologize if I'm too vague on what I'm trying to do. I've not worked with these types of things in quite a while. Any help is appreciated, thank you!

3 comments
Why not just make the invisible part face the correct direction, then use lookVector?
The invisible part does face the right direction. It's just that I don't know how to make the velocity of my part relative to the position of the invisible part.
I edited my answer