Hello,

I'm programming a basic firearm. Following the standard mathematics to develop a drawline function for the trajectory, I have gotten where I have desired to be. However, I was wondering how I would add a bias to the arithmetic to start the drawline in front of the Tool, instead of the handles center. Is there anyone who could fill me in here?

--// Using standard revolver mesh
function drawline(Gun, Position) --// endpos variable of Raycast
	local ShotDistance = (Gun.CFrame.p - Position).magnitude
	local Gunshot = Instance.new("Part"); Gunshot.Parent = workspace
	Gunshot.Anchored, Gunshot.Locked = true, true
	Gunshot.CanCollide = false
	Gunshot.Size = Vector3.new(.2,.2,ShotDistance)
	Gunshot.CFrame = CFrame.new(Gun.CFrame.p + 5, Position) 
    * CFrame.new( --// Same line
		0,0,-1.5 + (-ShotDistance/2)
	)
	game:GetService("Debris"):AddItem(Gunshot, .1)
end

The negative 1.5 is my bias, it puts the drawline in front of the barrel, yet, when I change my shot, let’s say to fire left or right behind me, it moves a few studs away from the barrel. I am not trying to get this affect, but I can deal with it. I was just wondering if there was a way I can permanently keep starting it one stud in front the barrel no matter which direction I fire.

Pathway: Player - Backpack - Tool - Handle (‘Gun’ variable)

3 comments

0

can i see video of whats happening?

0

I can’t send a video unfortunately, but the goal I’m trying to reach, is mainly like the revolver model in Twisted Murderer. This is the only functional example I can provide to my desired outcome, but if you take a look at how it fires, the transparent beam that resembles the bullet line, always begins in front of the barrel. Mine does too, yet if I face towards my character in third person

0

and fire, it shoots diagonally like it would if to start at the tip, yet it fires slightly further down the barrel and out