Advice needed on adding a new character controller.

So I’m working on a game that has the quirky mechanic of gravity being highly dynamic (like Super Mario Galaxy). The character controller provided by Bullet (and by all of the supported physics plugins, as far as I can tell) assume that gravity will either be axis-aligned or fixed to the Z-axis. This, of course, doesn’t work with my game mechanics. I’m currently working on modifying Bullet’s character controller (and Panda’s Python wrapper for it), but I’m having difficulty integrating it well into Panda. (Rotating the world instead of the character controller has its own issues, and isn’t a viable solution.)

The BulletWorld class makes the assumption that BulletCharacterControllerNode is the only type of character controller that will be used, so I am unable to attach my custom node to it (it has the wrong type). Should I just make a modified copy of BulletWorld that uses my custom node instead of the standard one, or is there a better/more extensible solution (like making a general CharacterControllerNodeInterface or the like)? Finally, given the answer to that question, what’s the best way to distribute these custom classes with my project?

So far (after testing a couple different approaches), nothing quite works. The best solution I can come up with at the moment is modifying the Panda source to use a general CharacterControllerInterface instead of the specific BulletCharacterControllerNode (in BulletWorld), such that Panda users can write their own character controllers based upon Bullet (which already has a characterControllerInterface header file).

If I do go this route (and succeed), how would I distribute this modified version with my program? It seems from the manual that some distribution methods download necessary packages from the Panda website (I think the web plugin does this?) - how do I force it to use my custom modifications instead of the official packages?

If you really need to fork Panda and distribute an application (or browser app) that relies on your fork, you can do this by hosting the entire forked Panda on your servers, and building your p3d file with that URL. But I don’t recommend doing this unless there’s really a good reason.

Instead, it would be better to design your changes such that they can be safely integrated back into the Panda trunk (that is, without breaking other applications), and submitting them as a patch.

Another possibility is to do all of your changes by subclassing existing Panda structures, so that your new code is a DLL that links with Panda. Then you can build your p3d file with the standard Panda trunk, and host only your custom DLL on your own server. This is preferable to hosting an entire copy of Panda for several reasons.

David

I didn’t consider that other users might want to implement their own character controller. This is a reasonable request, since most games want to have their customized character controllers. So we should support this.

I could add an abstract base class for controllers and amend methods in BulletWorld to work with this base class. But I would require these methods to be part of the interface, because they are used by BulletWorld and other classes:

BulletBaseCharacterControllerNode : public PandaNode {
public:
  virtual void sync_p2b(float dt);
  virtual void sync_b2p();

  INLINE virtual btPairCachingGhostObject *get_ghost() const;
  INLINE virtual btKinematicCharacterController *get_character() const;
}

BulletCharacterControllerNode : public BulletBaseCharacterControllerNode {
  ... current default implementation ...
}

Do you think you could get along with such an interface?

That’s practically what I implemented, with one difference: use btCharacterControllerInterface instead of btKinematicCharacterController. I, for example, made most of my changes at the Bullet level and (for the most part) left the Panda-level wrapper alone.

Thanks, by the way. :slight_smile: Panda’s a really well designed library, and being able to work in C++ and Python (the two languages I’m most comfortable with) has really helped the development process. Struggling with an engine or library really takes the wind out of my sails.

(I also fixed my physics issues, so I’m hoping to at least have a tech-demo working in the relatively near future. (If anyone’s played Psychonauts, it will feel similar.))

Ok, right, it should be btCharacterControllerInterface and not the implementation.

I will adapt the Panda3D source code one of the next weekends, since I am quite busy right now. This should enable you to work directly with the original Panda3D sources and simply extract your classes from there.