Ad
Log in to vote
0

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

Asked by 8 months ago

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

Log in to vote
0
Answered by 8 months ago

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)
Ad
Log in to vote
0
Answered by 8 months ago

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.

Answer this question