Basics Help

tl;dr: 2 main noob issues I’m trying to figure out, how to use Collision Bitmasks and How to completely terminate a bullet.

Edit: Jeez, realized this was my first post, thought I had posted before, but I guess I had been lurking. Hi! [/edit]

Hello, I’ve been trying to learn Panda and towards that end have been working on small little projects to demonstrate some key points.

In this case, the goal is a little top down spaceship shooter against other ships. I suppose like a variant of the asteroids demo that comes with Panda, but homegrown and tiny bit different.

So far, I have completed the following:
I have two two-poly models I was able to export from Blender 2.5x (no textures) - a ship and a bullet. I’m able to have the player’s ship controlled by wasd controls, and shoots with spacebar. An CPU ship currently is there to just fly in a circle to provide something to run into.

The current stumbling block is how to handle the collision. I’ve been working on figuring this out for about two weeks and just can’t seem to get it, yet. Half the terminology in the manual is as of yet lost on me, and while this was nice, it doesn’t help my issue that I can figure out.

[size=150]Issue 1[/size]

The problem is I have four types of objects, player ship, enemy ship, player bullet, enemy bullet. Player bullets should only interact with enemy ships and vice versa, but any two ships shouldn’t be able to collide. I figured this would be great with a collision bitmask, but I can’t get it to work.

When ever I fire a bullet, it collides with the ship firing it, but not the enemy, though inter-ship collisions work. What am I doing wrong? You can see the code here which calls on this class file, the two ‘models’ are here for the ship and here for the bullet. I know it’s a bit messy, but it’s not huge. I’ll be cleaning things up later, once I get a better feel on how to organize things and comment.

Also, am I putting the collision traversers and handlers in the right spots?

[size=150]Issue 2[/size]

After the bullet ends, I am getting rid of the model, but it seems the collision nodes remain… is there a way to get rid of both at the same time? I haven’t researched this as much, since the collision issue has been taking up the majority of my already limited spare time.

[size=150]Issue 3[/size]

Any other suggestions? It’s still very small, so it’s easy to change right now, plus I’d like to learn good techniques before I get too used to bad techniques.

At this point, I’ll take any thoughts I can get. I’ll continue to peruse the forums and manual in the meantime.


From what I understand (somewhat), you can either set an object’s collision mask to act as an “INTO” object, “FROM” object or Visible Geomerty (which is like exact collision checking using the objects geometry).



Visible Geometry used as a collision checker is freaking slow! Better off using a collision barrier/Octree for all collisions. Much faster!

You should make a habbit of attaching collision objects to the objects they Represent in collision. If you detach the Main Visible object, its collision goes with it.

Thanks for the help, but I’d already seen the documentation. Turns out I was able to bypass the bitmask issue by only assigning the bullets an into bitmask, and treating them more or less like moving environment pieces.

As to getting rid of the bullets, I’m using a model.removeNode() call on the bullets once they are ready to expire, and that seems to work. Since there is no from collision detection on the bullets, no worrying about that.

And as to the code, it’s now in five main modules and I’m making decent progress.

Now my current stumbling block is how to get the into-object to remove itself upon a collision. I’m able to get the collision event information, and that provides me with a connection to the into collision node, but in order to call a model.removeNode() on the model the collision node is attached to, I think i need a connection to that (and collisionNode.getParent() doesn’t work, and I don’t see any other options in the API). Thoughts?

Try this:




in your collision callbacks :wink:

Definitely tried that, every time I get a “AttributeError: ‘builtin_function_or_method’ object has no attribute ‘getParent’” error.

Edit: DangerOnTheRangr helped me realize it was due to a missing pair of parenthesis. I can finally sleep! Thanks for the help, guys.