Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to make raycast face lookVector?

No matter in which way i shape the code i havent been able to get the raycast to be perfectly oriented towards the lookvector.

The script outputs that the raycast is not hitting anything, which should not be possible considering the origin of the raycast is located within 6 walls, therefore the sky is not visible at all.

picture of where the raypart is located: (imgur.com/a/h7j1kZh)

Heres the code:

while true do
	local result = workspace:Raycast(script.Parent.startP.Position, script.Parent.startP.CFrame.LookVector)
	if result then
	local newpart = Instance.new("Part", workspace)
	newpart.Position = result.Position
	newpart.Shape = Enum.PartType.Ball
	newpart.Size = Vector3.new(0.1,0.1,0.1)
	newpart.BrickColor = BrickColor.Red()
	newpart.CanCollide = false
	newpart.CanQuery = false
	newpart.CanTouch = false
	newpart.Material = Enum.Material.Neon
	wait()
	newpart:Destroy()	
	else
		wait()
		warn("No raycast result!")
	end
end

Thanks to anyone that helps in advance

1 answer

✓ Accepted answer

You've given the RayCast a direction, but haven't given the direction a length.

As an example, adding * 5 to the direction will make it RayCast 5 studs in that direction.

script.Parent.startP.CFrame.LookVector * 5

2 comments

0

oh, i never understood what that * x meant at the end of it, ill check it out tomorrow and see if it works. also, just to tell you i sometimes with some solutions have an issue where the lookvector isnt exactly the face, sometimes its offset to the side and its rotation only matches up every 90 degrees so ill see if this solution works.

0

works perfectly and no offset, i cant thank you enough!

This discussion is preserved as it was. New answers, comments, and votes are closed.