"Invalid Direction. Must contain finite values" when trying to spherecast

I’ve tried looking around everywhere online and especially the devforum but have found no other people have had this issue. I’m trying to spherecast and I get this error only with the position and direction I’m using. There seems to be nothing wrong with what I’m inputting and this only happens when I try to spherecast/shapecast. My values work fine with normal raycasting. If anybody has come across this before or knows what’s going on and how to fix it your help would be appreciated,

local raycast = workspace:Spherecast(self.position, self.settings.boundsRadius, self.foward.Unit * self.settings.collisionAvoidDist, self.params)
--local raycast = workspace:Raycast(self.position, self.foward.Unit * self.settings.collisionAvoidDist, self.params)

Those are how I have the raycast’s setup. No idea why it only doesn’t work with shapecasting.

1 Like

Did you set the collisionAvoidDist to math.huge? That would mean you are trying to cast an infinitely long spherecast. For raycasts, that is possible, but not for spherecasts. Also, the maximum radius of a Spherecast is 256 studs and the maximum Direction distance is 1024 studs. My guess is you set the collisionAvoidDist to an infinite value?

Yeah I made sure its not over the limit. The collisionAvoidDist is equal to only 15. If I put in a normal Vector like this

Vector3.new(0, 10, 0)

I get no error for the direction but the position instead. Even though the position is normal. Is this maybe a bug with shapecasting?

Can you maybe tell me what that error is exactly. I don’t think shapecasting has been around for very long now, so bugs are definitely possible, but its still best to try and pinpoint the issue if possible. I just don’t have much information on your scripts, so I can’t tell you much more.

Just looked through the code and added some print statements. Now I’m noticing that some of the directions are nan, nan, nan. Which I would guess throws the error. I’ll try to see what causes it.

1 Like

Thanks for the help, I ended up just not using spherecast’s as I can use raycast’s and with the new math I’m doing I don’t need spherecast’s anyway. For some reason the math I’m using for flock behavior for my boids gives nan position and directions when two or more boids share the same position which throws errors only for shapecast and not raycast.

1 Like

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