The title says it all. I’ve got some ideas, some of which don’t even involve Raycasts, such as defining an invisible line in space, but then precision becomes difficult to maintain (At least which the ways I’m thinking of doing it).
For additional context: The enemies in this game are completely rendered on the client. There are no models on the server. I designed a function that gets the dimensions and position of the Enemy’s limbs on the server, given it’s position on the path.
Reasons I cannot create parts for the limbs and perform raycasting on them:
Those parts will get replicated to the client, sending even more positional data than I already am for the actual enemies. Although if anybody does know, I’m curious if deleting parts on the client reduces network reception when the same part is frequently moved on the server.
With 150+ Enemies, I could see this becoming a performance concern on the server.
In the image, there are yellow parts just to illustrate the bounds of the enemy’s model that I find given it’s position on the path.
hello . I assume you want the ray to go through invisible parts? If that is what you want , you can repeatly cast a ray . If the ray hit a part with transparency>= 1, cast another ray . If that is not what you need then pardon me
It is not. The parts don’t exist at all. They’re just there to illustrate the invisible boundaries of a box that does not exist. Where I then need to determine if a line or ray pass through it.
hmmm . The only idea I have is to:
1)make custom raycasy function (kinda a bad idea)
2)maybe have a cache folder where you store some bonding box of the rig. When you want to raycast, check if a cache part exist. If not , create one . If yes, use it
After some challenging math (at least for me), I’ve created a decent script that does what I wanted. I’m too lazy to explain where I got the math or my thought process, but I know others might find it useful, so I’m sharing it here. Feel free to ask any questions though if you have any.
local function IsRayIntersectingBox(RayOrigin: Vector3, RayEnd: Vector3, BoxCFrame: CFrame, BoxSize: Vector3, Params: RaycastParams): (boolean, Enum.NormalId)
local Direction = (RayEnd - RayOrigin).Unit
local Length = (RayEnd - RayOrigin).Magnitude
local Raycast = workspace:Raycast(RayOrigin, Direction * Length, Params)
local HalfSize = BoxSize / 2
local MinBound = BoxCFrame.Position - (BoxCFrame:VectorToWorldSpace(HalfSize))
local MaxBound = BoxCFrame.Position + (BoxCFrame:VectorToWorldSpace(HalfSize))
local TMin = (MinBound - RayOrigin) / Direction
local TMax = (MaxBound - RayOrigin) / Direction
local T1 = Vector3.new(
math.min(TMin.X, TMax.X),
math.min(TMin.Y, TMax.Y),
math.min(TMin.Z, TMax.Z)
)
local T2 = Vector3.new(
math.max(TMin.X, TMax.X),
math.max(TMin.Y, TMax.Y),
math.max(TMin.Z, TMax.Z)
)
local TNear = math.max(math.max(T1.X, T1.Y), T1.Z)
local TFar = math.min(math.min(T2.X, T2.Y), T2.Z)
return (TNear <= TFar and TFar >= 0 and TNear <= Length)
end