Warning: this tutorial is my best guess at making this idea in Panda3D. If anything is wrong feedback would be appreciated, and i hope you enjoy the tutorial.
Hey everyone, this is a tutorial detailing a concept of adding new collision types
to your Panda3D game. Panda has the ability to process basic geometry collisions
but inheriting from the objects that use the collision system was hard to do so i created
my own objects that i can use while collisions are detected to add additional behavior.
Now i can add things like a ghost trait to my character and have collisions react differently
in this program. The source code for this program is here: Github.com
This program has a setup of six files, in creating a character i start in the Character file.
The important things the character has are a Panda DirectObject for events, a model for
the game, XML data, and a collision object to store a CollisionNode and associated
information to make scripting new behaviors.
The file CharacterCollisionNode uses XML data that's given to it to make the new type
of collision with details for different reactions when the program does process collisions.
The file xmlcharacter is where i store the attributes i want the player to have. For my
programs in the future i might not send all of my XML to a collision type but instead
read some data and do something with that in the general object information.
Giving the tag <ghost> to the file gives the character the ghost attribute.
In the process file the main section of the program is executed. After creating a
character i store the collision object from it into a dictionary in the game instance.
I use the index of the collision node itself since it will be referenced in the same way
every time a collision is processed so its a easy way to access the rest of the data for
the specialized collision. The main program also loads an environment object and sets
a collide mask so the player object can collide with it but the environment doesn't have
a in-program shape like the player does.
GameSetup is the last file besides GlobalVariables which is a series of imports, and it's where the collision processing loop is. For every collision entry Panda
detects i check for the collision node in the customcollisions dictionary. Depending on the type
of the collision object different code sections are executed.