RayCast Offset From Fire Position

My raycast is offset from the Firing Position

Video

Raycast

		local Cast = workspace:Raycast(ShootPos,(MousePos-ShootPos).Unit*2000)

Raycast Visualizer

if Config.VisibleRaycastBullet.Value == true then
			if Cast then
				result = Cast.Position
			end
			local distance = (ShootPos - result).Magnitude
			local p = Instance.new("Part")
			p.Anchored = true
			p.CanCollide = false
			p.Size = Vector3.new(0.05, 0.05, distance)
			p.BrickColor = BrickColor.new("New Yeller")
			p.Parent = workspace
			p.Transparency = .5
			p.Material = Enum.Material.Neon
			p.CanQuery = false
			p.CanTouch = false
			p.CFrame = CFrame.lookAt(ShootPos, result)*CFrame.new(0, 0, -distance/2)
			local t = game.TweenService:Create(p,TweenInfo.new(Config.VisibleRaycastBullet.Time.Value),{Transparency = 1})
			game.Debris:AddItem(p,Config.VisibleRaycastBullet.Time.Value)
		end

image

Firepos is the selected

I almost went deaf from those gunshots lol

Are you sure your ShootPos is the exact the attachment position is?

Yes when I testing and select the firepos it is in the right spot, but the ray cast is not
image

local directionCF = CFrame.new(ShootPos, result)
p.CFrame = directionCF
p.Position += directionCF.LookVector * math.abs((ShootPos - result).Magnitude)/2

Try this instead

i tried that and it worked for the first like 15 shots then was offset again

Animations are being loaded on the client would that mean the position of the gun on animation does not replicate to server?

But it works for first few shots though so I don’t know what is wrong

i set animation id to 0 and now the shots fire correctly so something is happen with my animation even it it looped i’m gonna try it on server
image

wait, the bullet renders on server?

if it is so, you should know that client and server has not only the delay(ping), but animations are not synced too.

1 Like

Ohhh I just made the animations on the server script, and now it is working in the correct spots thank you for the help

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.