So I am making a gun for my game and I am using raycasting. I wanted to bullets to look like they are actaully moving instead of a line just appearing. So I wanted to make it so that when the gun is shot the ray starts small at the barrel of the gun and the length just gets larger until it hits the target. However once I did that the ray was the right distance but it just went through the target and looked like this
The yellow line is the ray and the wall was the target. So what I did next was try to make the ray only go halfway, and it did make the ray a little closer but not very much so here is the code. position is the position of the target and distance is the distance from the barrel of the gun to the target.
bullet.CFrame = CFrame.new(origin, intersection)*CFrame.new(0, 0, -1)
bullet.Parent = Workspace
local speed = distance/50
local tweenInfo = TweenInfo.new(speed,Enum.EasingStyle.Linear)
local goal = {}
goal.Position = Vector3.new(position.x, position.y, position.z/2)
goal.Size = Vector3.new(.2,.2,distance)
local TweenService = game:GetService("TweenService")
local tween = TweenService:Create(bullet, tweenInfo, goal)
tween:Play()