• Register

Panda3D is a game engine, a framework for 3D rendering and game development for Python and C++ programs. Panda3D is Open Source and free for any purpose, including commercial ventures, thanks to its liberal license. Go ahead and grab it here. To learn more about Panda3D's capabilities, visit the gallery and the feature list. To learn how to use Panda3D, check the documentation resources. If you get stuck, ask for help on the forums, our community is very active.

Post tutorial Report RSS Panda3D Tutorial: Creating New Collision Types

A tutorial on making more collision types in Panda3D.

Posted by on - Basic Client Side Coding

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.

notepad KqdZLxsaGv

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.

notepad 4ZYRsX8bdf

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.

xmlcharacter

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.

process 1

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.

GameSetup1

GameSetup2

Post a comment

Your comment will be anonymous unless you join the community. Or sign in with your social account: