Problem with raycasting

So I use this to simply weld this arrow union to the shield if it touches the shield but it always goes further.

-- ...
if raycastResult.Instance.Name == "Shield" then
		local copy = game:GetService("ServerStorage").Arrow:Clone()
		local weld = Instance.new("WeldConstraint")
		
		--weld.C0 = CFrame.new(raycastResult.Position, mouseHitP)
		weld.Part0 = copy
		weld.Part1 = raycastResult.Instance
		copy.Parent = workspace
		weld.Parent = copy
		
		Debris:AddItem(copy, 30)
	end

Tried normal weld with that C0 but I got similar results.

Try having an attachment on the front of the arrow, Getting the offset from the attachment position and the Arrow position. Then CFrame the Arrow to the raycastResult.Pos + the offset, then weld it, Sorta like this

local Arrow = Arrow:Clone()
local weld = Instance.new("WeldConstraint", Arrow or Shield)
weld.Part0 = Shield
--WeldConstraint = weld but without screwing over position
ArrowOffset = Arrow.Attachment.Position (since it already is the offset)

Arrow.CFrame = CFrame.new(RaycastResult.Pos + ArrowOffset) --Positioning Arrow with offset
weld.Part1 = Arrow
Arrow.Parent = --Put Arrow Parent Here

--If all goes well, the Arrow will still have the same rotation value
--and it will stick in there

Thats what I would do, Instead of using a weld, position the Arrow first then put it on a weldConstraint

1 Like

image
It’s vertical now, if I set it like this,

if raycastResult.Instance.Name == "Shield" then
		local copy = game:GetService("ServerStorage").Arrow:Clone()
		local weld = Instance.new("WeldConstraint")
		weld.Parent = raycastResult.Instance
		weld.Part0 = raycastResult.Instance
		local ArrowOffset = copy.Attachment.Position
		copy.CFrame = CFrame.new(raycastResult.Position + ArrowOffset)
		weld.Part1 = copy
		copy.Parent = raycastResult.Instance
		
		Debris:AddItem(copy, 30)
	end

image

I would get the Direction of the ray somehow, extend the Direction by a bit from the Arrow and make the Arrow point towards the direction using CFrame.new

sorta like

function CastRay()
	local Direction
	local raycastResult = Casted
	if raycastResult.Instance.Name == "Shield" then
			local copy = game:GetService("ServerStorage").Arrow:Clone()
			local weld = Instance.new("WeldConstraint")
			weld.Parent = raycastResult.Instance
			weld.Part0 = raycastResult.Instance
			local ArrowOffset = copy.Attachment.Position
			copy.CFrame = CFrame.new(raycastResult.Position + ArrowOffset)
			weld.Part1 = copy
			local newPos = copy.Position + (Direction.Unit)*10
			copy.CFrame = CFrame.new(copy.Position, newPos)
			copy.Parent = raycastResult.Instance
			
			Debris:AddItem(copy, 30)
	end
end

Use the Direction variable from earlier in the function

1 Like

That, unfortunately, didn’t work. Do you have any more suggestions?

is your front face on the arrow the front of the arrow? Wdym didnt work? Did it do it but it be sideways?

image

I dont have any more suggestions… Hopefully someone else does…

1 Like