Collision Detection Problem

Hi, I would like to know how to detect collision through a 3D model instead of a collision sphere, tube, etc. So whenever the model runs into something (and the something would also have its own collision detection instead of a collision sphere, tube, etc. inside of it), it would be more efficient with it not going through it at all instead of going through it a little bit until the actual collision sphere, tub, etc. touches it. Thanks in advance!

First of all, I’m not sure that you mean “efficient” (that is to say, “less wasteful of resources”–and thus likely faster)–do you perhaps mean “effective” (that is to say, “looking better”)?

In Panda’s collision system, I believe that polygon-to-polygon collisions are far less efficient than collisions using the basic shapes provided. Additionally, I don’t think that such polygonal collision geometry responds to bone-animation, meaning that your collision geometry won’t match any animations that you might have.

It’s possible that one of the other collision systems, such as Bullet, has an answer to this–I don’t know, I’m afraid.

My suggestion is to use “exposeJoint” to gain NodePaths connected to major bones, and to then attach appropriate basic shapes to those NodePaths in order to reasonably approximate your geometry.

Again, it’s possible that there’s an easier or better way made available in one of the other collision systems, but I defer to others on that point.

But what about a way that adds collision to each of the polygons/vertices on a model, so even if it is animated, it will detect collision wherever any polygon is. As such, I can’t do it with bones especially because of using environmental models, such as buildings, etc.

First of all, are you using Panda’s collision system? My answer below presumes that you are, and elements of it may be mistaken or simply a little different when using other collision systems.

That said, static (that is, non-animated) models are relatively easy: YABEE at least can observe game-logic tags added in Blender, including the “Collide” tag (as described here–look for “Collide” under the section “Grouping Entries”–you probably want “polyset keep descend” as your tag values); I imagine that the other exporters have similar functionality. Otherwise, you can simply add the “Collide” tag to your egg files.

A word of warning, however: if your models are of fairly high resolution, this can be relatively inefficient; it might be worth creating separate, less-complex geometry specifically for collision purposes.

As for animated models, I honestly don’t know–I’ll defer to those who know these things better than I on that point, I believe. As I said, I don’t think that Panda offers that functionality out of the box for models animated by bones.

You mentioned that you don’t want to attach colliders to bones because you also have non-animated models–why not just use one approach for animated models, and another for non-animated models? That might allow you to use exported polygonal collision geometry for static objects, and primitive colliders attached to bones for animated objects.

Hi, what you said barely makes any sense to me. Also, I never said I didn’t want colliders attached to bones. I just said I wouldn’t be able to do that with objects such as buildings because they don’t need bones.

Also, the manual page you linked only shows egg file syntax, not collisions.

What I need is for collisions to be detected through the model and its vertices/polygons, not a collision sphere or any other basic collision shape inside a model, so the collision is more accurate. In any way this can be done, please explain it to me, and I will greatly appreciate it. :slight_smile:

Thaumaturge is pointing in the right direction. With the “polyset keep descend” tag you are telling the loader to build a collision polygon for every polygon of your model.
That’s not the only way to build collision polygons for your model, you can build them one by one from sets of verts if you want, but the “polyset keep descend” tag is by far the most simple way.

Keep in mind that polygon/polygon collisions don’t work that good (or in fact at all), so some of your collision objects (players, npc, etc) must be modeled from spheres, rays and tubes. If the models are animated then attaching spheres and tubes to bones is the only way to go if you want accurate(-ish) collisions.

You said, I believe (emphasis mine):

Which seems to imply that, well, you’re not in a position to use bones, and thus to use things attached to bones. In particular, the term “especially” implies that attachment to bones is not at all an option for you, with static objects being a particularly significant case, not the only one.

Fair enough; aside from things answered in either this or Wezu’s post, is there anything specific that you want me to elaborate on or re-phrase?

I understand this; as I’ve said, I’m not sure of how it might be done in the specific case of animated objects, and warn you that it might be slower than other methods either way. Hence I’m attempting to answer your question while also suggesting other potential paths–after all, how likely is it that, in a collision with an animated character, the difference between colliding with the exact polygons used for the visible model and a reasonable approximation via appropriate primitives (such as capsules for arms) will be all that noticeable?

It may well be that you have a case in which it will be noticeable, in which case fair enough–but not knowing your specific case, I’m attempting to help by providing more options to you.

As Wezu pointed out, part of that syntax covers how one specifies collision geometry in a model.

Hi, thanks for helping guys! I must have been tired when I said that stuff doesn’t make sense. It all makes sense to me, and I’ve done a little bit of research, and had a few conversations in the IRC channel about it. I figured out about how it all works and how I need to do it. Thanks again for your help! Every little bit of information (including yours) helps a lot. :slight_smile:

Ah, I’m glad that you did! For my part, it was my pleasure. :slight_smile:

If I may ask, for the sake of my curiosity and for anyone else who might come here looking for answers to similar questions, what did you settle on in the end?