Blender collision geometry and animations

I went through the roaming Ralph sample and found out that the model must have collision geometry and not your program. So how do I add collision geometry in Blender so that my collision detection works?

Also, how do I export animations and actions with the YABEE exporter? I tried it but only one egg file is created, without the animation.

(In this response I’m going to presume that you’re using Blender 2.7, and the appropriate version of YABEE to that version of Blender. If you’re using a newer version of Blender, then I’ll leave the question to another, as I’m not familiar with either the newer Blender or the version of YABEE that goes with it.)

That’s not necessarily true; both approaches can work.

However, for complex objects like terrain it can indeed be easier to build custom collision-geometry in Blender and export it with your model.

In short, as with many Panda tags, this is handled in Blender by applying “Game Properties” to your model. Specifically, collision geometry is indicated via the “Collide” tag.

To do this:

  • Model your collision geometry in Blender, and select it.
  • Open the “Logic Editor” view, and open the “Properties” panel if it isn’t already open.
  • In that panel, click on the button labelled “Add Game Property”. This results in a set of fields appearing below the button, which specify the game property in question.
  • The first field is the name of the property, and likely starts off with the value “prop”. Change this to “Collide”.
  • The second field is the type of the property. If it isn’t already “String”, change it to that.
  • The third field is the value of the property. For standard, solid collision geometry, give it the value “polyset descend”.
  • Now export–you should have collision geometry!

To explain the value given to the tag, if I recall correctly:

  • The value “polyset” indicates that we’re creating polygonal collision geometry.
    • We could instead indicate that we’re defining a sphere, or some other shape.
  • The value “descend” indicates that this should apply to any objects parented below the current one. (I think; I’m not sure that I have that quite right.)

There are other elements that we could add, too. For example, we could add “intangible” if we want the collision geometry to be non-physical.

For more information, see here.

There are two ways:

  1. Specify your animations as pairs of start- and end- frames on your animation timeline, or
  2. Specify your animations as actions in Blender’s “Action Editor”.

If you use the first approach, make sure that you do not have “All actions as animations” checked. Then, use the “plus”-sign just below that check-button to add animation entries to the box beside said “plus”-sign. For each entry, fill in the relevant data in the fields that appear below the box.

If you use the second approach, make sure that you do have “All actions as animations” checked. In this case, no more should be required; all “actions” specified in the “Action Editor” should be exported.

How would you add collision in python, without adding collision geometry in Blender, when I add it and print out all collision entries, the list is empty. However, in the program, clearly it is colliding.

How do I export indivisual actions (not animations)? Do I enable all actions as animations? Where is this check box? Like the Ralph walking and running actions in the default sample models. Do you add that to timeline as well? How do you add action/animation to timeline?

That suggests to me that the collision geometry is being successfully added, but that there’s a problem with the code that sets up the collision-handler.

If you want an example of setting up some collision geometry, as well as setting up collision-events and a collision-queue, you might look at my “beginner’s tutorial”, specifically the lessons that cover the collision system. Starting here:

In this case, actions are animations.

I don’t think that there’s a means of exporting just one action. But you could always experiment; perhaps it can be done by selecting just one action, then exporting by key-frames rather than by selecting “All actions as animations”.

Exactly, yes.

I believe that the YABEE “how-to” document (which should be found on the same GitHub page on which YABEE is hosted) includes a screenshot that shows it.

When you switch between actions in Blender, you should find that the timeline updates to reflect only the key-frames belonging to that action, I think.

It might be worth looking up a Blender tutorial on creating actions, as describing the process here could become tricky (lacking screenshots or video), and a little lengthy.

But in short:

  • In Blender, open the “Dope Sheet” panel. (From the list of panels that includes the 3D view, UV/Image editor, Properties panel, and so on.)
  • From the drop-down to the right of the various menus in that panel, select “Action Editor”.
  • Now, for each animation:
    • Go to the section just to the right of the above-mentioned drop-down, and add a new action.
    • Name this action; the name given should end up as the name of the animation.
    • Click on the button labelled “f”–this prevents the action from being removed if Blender thinks that it’s not being used!
    • Insert key-frames as usual; with the action selected, they should be assigned to it.
1 Like

Thanks for that amazing tutorial! It now works! Is there one for CollisionHandlerQueue? And do both the objects need to have a collider?

It’s my pleasure! I’m glad if it’s proving useful! :slight_smile:

That’s excellent to read! :slight_smile:

One of the later lessons makes use of CollisionHandlerQueue, indeed. I think that it’s one of the lessons that involves the implementation of a laser, so if you page forward a few lessons you should find it.

Generally speaking, yes.

However, be careful! The more “active” colliders there are–that is, colliders that are registered with a handler, and which the system checks against all others–the more work the collision system has to do, and the more impact there may be on the performance of the game. Thus, it may be worth trying to limit the number of “active” colliders, instead having others be “inactive”.