- Home /
Why is CapsuleCast/Raycast performance effected by rigidbody?
I am doing some big number testing for collision detection with a MMO authoritative simulation server, and am curious as to why I am getting the results I am getting.
Basically I am running a test where I do 100000 capsule casts (which would be a weapon swing) in a scene with 3000 capsule colliders (simulating the hitboxes of the players) When the colliders do not have rigid bodies attached, unity executes it in approx .35 seconds.
When the colliders HAVE rigid bodies, it takes nearly 8 seconds... a huge difference. I have the rigid bodies set as kinematic, and am just really confused as to WHY this is the case considering CapsuleCast(), i believe, doesn't take rigid bodies into account and definitely works fine without them in the scene.
The same is true for raycasting without RigidBodies, RayCastAll() takes .12 seconds, and with them it takes 1.5 seconds to execute.
(just as a disclaimer before someone says it, this is not due to rigid bodies simply being in the scene either, because if I don't do any sort of casting then it takes .02 seconds to play the scene)
Thanks so much for the help!
Richard
--As a follow up, it doesn't effect performance if the rigid body is only in the root of the object, or on ALL the child components (legs, head, torso, etc)... both yield the same execution time. If there is any rigid body attached to the colliders, performance goes down by 1000%... lol, help.
Answer by MakeCodeNow · May 15, 2014 at 11:10 PM
You'd have to ask a PhysX or Unity developer to get the real answer, but I'd bet that internally the capsule is converted into a planar convex shape when the RB is added (i.e. "triangulated" into a simpler planar approximation). Some physics engines do that because it's faster or more stable for the RB dynamics, but could definitely be slower for ray and capsule casts.
isn't a capsule already convex? And how would that effect the cast time?
A capsule is convex, but they may "triangulate it" so that it's a collection of planes that are an approximation of the original capsule. I've edited my answer to be more clear.
Your answer
Follow this Question
Related Questions
Possible to Give Rigid bodies collision bounding boxes? 0 Answers
Capsule Cast Direction Help 1 Answer
RigidBody stuck on wall when jumped against 7 Answers
rigidbody simulation collision check frequency check control?? 0 Answers
Raycast doesnt detect object in front of rigidbody (player is stuck on wall) 1 Answer