Scripting Helpers is winding down operations and is now read-only. More info→
Log in to vote

Making a raycast stop inside of a region3?

Asked by 8 months ago

Lets say you have a boundary of a region3

a square region3 with the size of 100,100,100 if a player had shot the raycast

is there any way I can calculate the distance so that it stops inside of the region3 instead of going outside?

The reason why i want to do this is because I dont want to use parts to detect collision

actually I do not want to detect any collision at all

so basically

I want an raycast to stop if it is outside the region3 or before it goes outside

kind of like using an part to stop an raycast except for this i need to calcualte the magnitude of the raycast before hand so that it perfectly stops right before it intersects or passes the reigon3?

There's no way to "stop" a raycast. You can either put walls at the edge of region3 or check if intersected part is outside the region3. T3_MasterGamer 2189 — 8mo
(squareMiddle.Position - raycastStart.Position).Magnitude - if you use that for the raycast length, it will stop the raycast once it's in the middle of the square blowup999 659 — 8mo
^ Also, if you can assume the region3 is a sphere instead of a cube, you can do (squareMiddle.Position - raycastStart.Position).Magnitude - squareSize.X and it will stop at the boundary of the sphere instead of the center blowup999 659 — 8mo

Answer this question