Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

What's the best way to find the position of the end of a gun's barrel?

I'm trying to code guns for a game and i want to have the bullets come from the end of the gun's barrel but i can't think of a way to get the position of the end of the barrel without welding an invisible part to the end. any better ideas?

2 answers

✓ Accepted answer

If it is a part, then get the paths for the position of the barrel. if its a meshpart, then get the position of the mesh part then add vector3 coordinates on top of the position. Change the vector3 value until it's just right.

local Meshpart = Path
local tool = script.Parent
local function OnShoot()
	local bullet = Instance.new("Part")
	bullet.Position = Meshpart.Position + Vector3.new(0,0,2)
end

tool.Activated:Connect(OnShoot)

This is a very specific question since every single model is different.

If it's a mesh / meshpart / union, then you're gonna have to use an invisible part.

If it's a model, then if there is a barrel part, you can just do

local barrelPart = path

print(barrelPart.Position) -- gives you the position.

There are plenty of other ways to do this, but since you did not provide us with a model, these are the only options I can give you.

This discussion is preserved as it was. New answers, comments, and votes are closed.