- Home /
CapsuleCastAll fails after 20 calls
I'm using Physics.CapsuleCastAll for my game's melee attack system. After 20 calls, it starts returning 0 collisions every single time. I can even put in a loop like this to speed testing:
for (int i = 0 ; i < 21; ++i)
{
RaycastHit[] results = AED.Cast(_args.Activator);
Debug.Log("Hit " + results.Length + " objects");
foreach (RaycastHit target in results)
{
if (target.collider.gameObject == _args.Activator.gameObject) continue;
_args.Activator.NotifyMadeAttack(target.collider.gameObject);
}
}
In this loop, the Debug.Log value will get 20 valid hits in a row, followed by a single "Hit 0 objects" result. If I attack again, all 21 attempts will come back with 0 hits. I've also done this manually, i.e. not looping my hit-check code, and it still starts failing on the 21st call. Is there a pool I have to clear or something?
I'd guess that Notify$$anonymous$$adeAttack does damage and kills the object's ability to register as a hit object after some point.
Notify$$anonymous$$adeAttack doesn't kill or remove any objects. It just notifies the attacker that the hit landed, and at present it's an empty stub. I'll also add that collisions fail for EVERYTHING in the world after the 20th call, not just the one thing I was hitting. The same thing happens if I hit one object 10 times and then another object 10 times...all casts after that return nothing.
Answer by rah · Feb 18, 2013 at 11:09 PM
Found the issue - float error was accumulating in the Z value until the collision test was beside my tiles (this is a sideview, orthographic project).
In the Z value of what? I don't see anything that your test code is reusing. I'd love to understand this problem better before I run into it in my own game, so if you could elaborate, that'd be great!
Your answer
Follow this Question
Related Questions
Test stationary capsule against colliders in scene. 2 Answers
How to use the new Physics2D.OverlapCapsule & CapsuleCast 0 Answers
Ways to work around OnCollisionStay/Enter events firing one frame late? 2 Answers
Is the CapsuleCast function broken? 1 Answer
CapsuleCastNonAlloc not filling results buffer in 2018.2 0 Answers