Im implementing an AI system based on the ScriptableObjects AI tutorial. I have found a weird problem, after half a minute or something, the casts I use to check if the player character is “visible” stops working. The NPCs see the player a couple of times, but then they no longer see it. HEre is my code:
I also tried replacing BoxCastAll by SphereCastAll, but the result is the same: after a while, the casts cant detect the player even when it is right in front of the NPC (or very close in any direction). Can somebody see something wrong here?
I tried that (I checked how many hits returned before the filter) and it is 0. For some reason, the cast works, and then simply stops detecting anything.
I am getting problems with capsule cast too ,it just doesn’t register nearby or touching object at all (I’m using unity 2019.1.3f1) Don’t know what’s the problem with it:rage:
This problem may be something I’ve encountered before, but it’s been a long time so I might not remember the details. If you look at the documentation for SphereCast, though:
In the notes it says: SphereCast will not detect colliders for which the sphere overlaps the collider.
It does not say anything like this in the BoxCast documentation, but I imagine they both work in a similar way.
Evidently, what that note means is that any colliders inside the sphere in it’s starting position are excluded from the results. Assuming BoxCast works the same way, you might try doing an OverlapBox at the starting point, in addition to the BoxCast, and then loop through both sets of results.
I think that BoxCastAll does detect objects in its starting position. At least, I noticed that the NPC object was detected, and I solved that by reducing the box in the Z axis to 0.5 or something like that.