Bizzare "range limit" for raycast(?)

I’m making a raycast on a loop that shoots straight down and using the result to position an attachment for a beam effect

It seems to not hit the ground until a certain distance. (~150 studs or so as I’ve tested I’ve positioned it under different objects with different heights)

Here is a video link that shows it only working on a certain height (the print only works if the raycast hits something, its in an if statement): https://youtu.be/JjU3bzsgBUA
(In the video it always hits a not-so-constant 200 studs before working)

I’ve tried moving the raycast down, looking on the forum, and changing the angle but no luck.

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

This is the “while true” loop in the script I’m talking about

while true do
	local mPos = script.Parent.Missile.Position
	local result = workspace:Raycast(Vector3.new(mPos.X,mPos.Y-3,mPos.Z), Vector3.new(0, -180, 0))
	if result then
		print(part.Position.Y)
		part.One.WorldCFrame = CFrame.new(Vector3.new(result.Position.X,result.Position.Y-1,result.Position.Z))
	end
	wait(1/45)
	--print(part.One.WorldPosition)
end

workspace:Raycast(Vector3.new(mPos.X,mPos.Y-3,mPos.Z), Vector3.new(0, -180, 0))
First part Vector3.new(mPos.X,mPos.Y-3,mPos.Z) is from where ray should start.
Second part Vector3.new(0, -180, 0) is direction in which ray is casted AND also a ray length limit. In your case ray’s length is 180 studs. You can make it Vector3.new(0, -1000, 0) and this will result in 1000 stud long ray, but be carefull, cuz repeated raycasts on long distance will be laggier than shorter ones.

1 Like

so X and Z are for direction while Y is for range? or are they all ranges and dont actually edit the rotation? im kinda confused

Raycast goes from Start to Start+Direction. Entire Direction Vector is used for ray length, not just Y.
To understand it better, try to instance part at the ray start, and at Start+Destination. You will see where ray will raycast.

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