Panda3d Collisions made simple

Return to Code Snippets

Panda3d Collisions made simple

Postby astelix » Thu Dec 17, 2009 12:41 pm

I packed a bunch of snippets showing how panda3d collisions works, split in ready to go standalone scripts, organized with progressive difficulty were you should learn the basics for prepare setups to make your scripts react when models collide each other, how to settle those models in a script and also in Blender3D.
Here a small summary of each step you'll find in the package:

-- Beginner level
A first approach with Panda3D collisions
0) quick startup
1) first very simple setup
2) simple setup with masking discrimination
3) collision events
4) collision events w/ masking
5) mouse picking
6) more mouse picking
7) cheap collisions with isInVIew
8) panda physics overview
9) mouse picking in 2D space

-- Intermediate level
Deeper into the topic
1) steering an avatar on uneven ground
2) avatar on uneven ground colliding w/ walls
3) gravity collider
4) collision mesh octree

-- Advanced level
Real-world application samples
1) real-world use of isInVIew: cheap intruder detection
2) 2.5D collisions: colliding 2D & 3D objects
3) target shooter minigame - simple physics ballistic (sorta)

You may snatch all the stuff, scripts and the blender sources, clicking the following links:
BEGINNER PACKAGE
INTERMEDIATE PACKAGE
ADVANCED PACKAGE

Pieces Of Advice:
  • This tutorial is devised to be attended in conjunction with the Blender3D modeler files, therefore if you're accustomed with a different one, i.e. maya or 3d studio max, I suggest you to download Blender3D nonetheless, study how the sources are structured and then try to reproduce in your beloved modeler.
  • So far the Chicken exporter do not correctly export collider nesting deeper that 1 level, therefore the descend feature stops there. Check here for more.


Beside this stepped tutorial is actually finished it is always perfectible, therefore drop a post to this thread if you find issues and questions blocking you to get what's going on in a particular point of the tutorial or blender sources.
Last edited by astelix on Mon Feb 13, 2012 3:27 am, edited 16 times in total.
My Rig:
P3D 1.7.0@WinXP & Kubuntu 10.04- Athlon 64 5200 X2 ~ Radeon 3200HD (integrated)
User avatar
astelix
 
Posts: 866
Joined: Mon Mar 27, 2006 4:36 pm
Location: Milano, ITA

Postby ambyra » Thu Dec 17, 2009 5:53 pm

Great! This is exactly the kind of thing I could use. I've been afraid of collisions for a while, but looks like I have no choice now.

I don't understand this part of the code:

Code: Select all
#** this is where will be periodically tested the collision
def traverseTask(task=None):
  for i in range(cHandler.getNumEntries()):
    entry = cHandler.getEntry(i)
    name = entry.getIntoNode().getName()
    dlight.setColor(VBase4(0.8, 0.8, 0.8, 1))
    if task: return task.again

  dlight.setColor(VBase4(0.0, 0.0, 0.0, 1))
  if task: return task.again


The top block is skipped if range(cHandler.getNumEntries())==0, right? But then what is the point of entry and name? I # them out, and the program still works. Is it for (potentially) checking to see what different objects collided with the smiley balloon?

Also, wouldn't it be clearer if you masked your heart with a LOVE_MASK like the red smiley instead of just a 1?
ambyra
 
Posts: 130
Joined: Sat Sep 20, 2008 5:47 pm

Postby astelix » Thu Dec 17, 2009 7:11 pm

how less better had you learn it if I ain't put 'on purpose' those litl mistakes, eh?
jokes apart your points are correct, and now I corrected, commented more that part you noted and repacked the zip - keep posting if you find how to improve or find other stuff to fix.
Last edited by astelix on Fri Dec 18, 2009 8:43 am, edited 1 time in total.
My Rig:
P3D 1.7.0@WinXP & Kubuntu 10.04- Athlon 64 5200 X2 ~ Radeon 3200HD (integrated)
User avatar
astelix
 
Posts: 866
Joined: Mon Mar 27, 2006 4:36 pm
Location: Milano, ITA

Postby ambyra » Fri Dec 18, 2009 12:41 am

I would like to see a pusher in the next version, like a sad face that you can push around. Maybe even a physics collision would be cool. With that you'll have covered most of the beginning problems people have with collisions.

Thanks for putting this together. It helps a lot! When its done I'll fix the grammar for you. I wish there were more collision examples available. This one could be really good (haha, maybe even 'official' tutor material :wink: ).
ambyra
 
Posts: 130
Joined: Sat Sep 20, 2008 5:47 pm

Postby astelix » Fri Dec 18, 2009 8:42 am

ambyra wrote:I would like to see a pusher in the next version, like a sad face that you can push around. Maybe even a physics collision would be cool. With that you'll have covered most of the beginning problems people have with collisions.


well good to know that - I feared was too thin to be useful so I'm glad for it.

ambyra wrote:Thanks for putting this together. It helps a lot! When its done I'll fix the grammar for you.


I don't get: "when it's done" what? if you referring to the package it is already fixed and uploaded yesterday.

ambyra wrote:I wish there were more collision examples available. This one could be really good (haha, maybe even 'official' tutor material :wink: ).


By the way try to speak what you got in mind to cover on the subject so I'll see to fix an 'advanced' sample later.
My Rig:
P3D 1.7.0@WinXP & Kubuntu 10.04- Athlon 64 5200 X2 ~ Radeon 3200HD (integrated)
User avatar
astelix
 
Posts: 866
Joined: Mon Mar 27, 2006 4:36 pm
Location: Milano, ITA

Postby ambyra » Sat Dec 19, 2009 3:39 pm

Sorry, I saw your changes. I meant that when a bunch of cool things like pushers and physics are added in.
ambyra
 
Posts: 130
Joined: Sat Sep 20, 2008 5:47 pm

Postby astelix » Sun Dec 20, 2009 8:22 pm

ambyra wrote:Sorry, I saw your changes. I meant that when a bunch of cool things like pushers and physics are added in.

ah ok, cool - that pushers thing is something I'm actually missing so I guess will be quite interesting for me as well.
My Rig:
P3D 1.7.0@WinXP & Kubuntu 10.04- Athlon 64 5200 X2 ~ Radeon 3200HD (integrated)
User avatar
astelix
 
Posts: 866
Joined: Mon Mar 27, 2006 4:36 pm
Location: Milano, ITA

Postby astelix » Mon Dec 21, 2009 5:56 pm

today I reedited the sample splitting it in 2 pieces and commenting out a lot much for the very beginners hoping to make it clearer than before.
My Rig:
P3D 1.7.0@WinXP & Kubuntu 10.04- Athlon 64 5200 X2 ~ Radeon 3200HD (integrated)
User avatar
astelix
 
Posts: 866
Joined: Mon Mar 27, 2006 4:36 pm
Location: Milano, ITA

Postby ambyra » Mon Dec 21, 2009 9:59 pm

I like the new two item setup! There's a problem, however, that will get people confused regarding your from and into objects. You make your hearts 'from' objects and your faces 'into' objects. The manual says to make the moving objects 'from' objects. I know this is because of your camera trick, but you should note that in the code. Otherwise, it's a very good example. Thanks for the new version!
ambyra
 
Posts: 130
Joined: Sat Sep 20, 2008 5:47 pm

Postby astelix » Tue Dec 22, 2009 4:44 am

ambyra wrote:I like the new two item setup! There's a problem, however, that will get people confused regarding your from and into objects. You make your hearts 'from' objects and your faces 'into' objects. The manual says to make the moving objects 'from' objects. I know this is because of your camera trick, but you should note that in the code. Otherwise, it's a very good example. Thanks for the new version!


well thankyou again - about the from into issue, did YOU get confused? I ask you cos all is commented with fine grain detail so, unless I used bad english, I ain't fear of that but lemme know otherwise.
My Rig:
P3D 1.7.0@WinXP & Kubuntu 10.04- Athlon 64 5200 X2 ~ Radeon 3200HD (integrated)
User avatar
astelix
 
Posts: 866
Joined: Mon Mar 27, 2006 4:36 pm
Location: Milano, ITA

why

Postby jbskaggs » Tue Dec 29, 2009 11:17 am

Code: Select all
#* to have collsions, the engine uses the model geometriy but to optimize the execution time is common practice to use simplified geometries - in our heart egg file we have provided a simple sphere to use for this purpose (look into he blender source to know what I mean) and so we'll gather it from there...
c = heartTrigger.find("**/collider")


Why is the method faster?

JB
That's the last time I use peanut butter nougat for the neuron processors in my robot!

JB Skaggs
User avatar
jbskaggs
 
Posts: 235
Joined: Thu May 07, 2009 11:10 pm
Location: kansas

Postby astelix » Tue Dec 29, 2009 11:28 am

cos' simpler is better
that means to make collision detection on lower polycount surfaces and simpler geometries is less CPU demanding - anyhow here you'll find a finer explanation: http://www.panda3d.org/wiki/index.php/Collision_Solids
My Rig:
P3D 1.7.0@WinXP & Kubuntu 10.04- Athlon 64 5200 X2 ~ Radeon 3200HD (integrated)
User avatar
astelix
 
Posts: 866
Joined: Mon Mar 27, 2006 4:36 pm
Location: Milano, ITA

Postby astelix » Sun Jan 03, 2010 12:01 pm

Today I updated and added 2 more samples to the pack - the new samples do the same things as the formers but in a different, clean and more efficient way using collision events instead to read from a collision queue. Check them out downloading the pack off the first post and of course report what's wrong or that may be done better.
My Rig:
P3D 1.7.0@WinXP & Kubuntu 10.04- Athlon 64 5200 X2 ~ Radeon 3200HD (integrated)
User avatar
astelix
 
Posts: 866
Joined: Mon Mar 27, 2006 4:36 pm
Location: Milano, ITA

Postby astelix » Sun Jan 10, 2010 10:09 am

Another addition of two steps - this time you'll see how to use collision events for mouse picking using a little more fancy string patterns.
My Rig:
P3D 1.7.0@WinXP & Kubuntu 10.04- Athlon 64 5200 X2 ~ Radeon 3200HD (integrated)
User avatar
astelix
 
Posts: 866
Joined: Mon Mar 27, 2006 4:36 pm
Location: Milano, ITA

Postby ravenaraven » Mon Jan 18, 2010 2:30 pm

Thanks astelix for the code. I'm trying to understand how collisions work and your example makes a fine sandbox.

Just a typo fix, if you allow me. The global variable pickingEnabledObject misses its 'b' (pickingEnabledOject) in the step6.py file. It does not affect it in anyway.
User avatar
ravenaraven
 
Posts: 2
Joined: Sat Aug 29, 2009 3:31 pm
Location: Sao Carlos, SP, Brazil

Postby astelix » Mon Jan 18, 2010 3:10 pm

ok thanks
btw I'm open for requests for expand the snippet chain so let me know if you got in mind other collision topics to cover
My Rig:
P3D 1.7.0@WinXP & Kubuntu 10.04- Athlon 64 5200 X2 ~ Radeon 3200HD (integrated)
User avatar
astelix
 
Posts: 866
Joined: Mon Mar 27, 2006 4:36 pm
Location: Milano, ITA

Postby astelix » Tue Jan 26, 2010 5:13 pm

today I overhauled the whole stuff and added a couple of snips talking about wall and floor collisions - grab and see if interested
My Rig:
P3D 1.7.0@WinXP & Kubuntu 10.04- Athlon 64 5200 X2 ~ Radeon 3200HD (integrated)
User avatar
astelix
 
Posts: 866
Joined: Mon Mar 27, 2006 4:36 pm
Location: Milano, ITA

Postby ambyra » Wed Jan 27, 2010 12:48 am

WOW! This stuff is great. Thanks astelix!
ambyra
 
Posts: 130
Joined: Sat Sep 20, 2008 5:47 pm

Postby treeform » Wed Jan 27, 2010 6:32 pm

When could we include this in the samples?
User avatar
treeform
 
Posts: 2106
Joined: Sat May 05, 2007 5:15 pm
Location: SF, CA

Postby astelix » Thu Jan 28, 2010 6:05 am

hey thankyou guys for the appreciation
treeform I guess is still incomplete to find a place in the official samples bunch - to me need at least to put in some 'fluid' sample and the gravity collider handler. Anyhow I think soon to fill the gaps.
My Rig:
P3D 1.7.0@WinXP & Kubuntu 10.04- Athlon 64 5200 X2 ~ Radeon 3200HD (integrated)
User avatar
astelix
 
Posts: 866
Joined: Mon Mar 27, 2006 4:36 pm
Location: Milano, ITA

Postby astelix » Wed Feb 03, 2010 10:57 am

today I added a new snippet regarding the CollisionHandlerGravity class and how to use it to spice up a scene. Go up to grab it
My Rig:
P3D 1.7.0@WinXP & Kubuntu 10.04- Athlon 64 5200 X2 ~ Radeon 3200HD (integrated)
User avatar
astelix
 
Posts: 866
Joined: Mon Mar 27, 2006 4:36 pm
Location: Milano, ITA

Postby astelix » Sat Feb 06, 2010 12:11 pm

step10 added: how to octreefy a collision mesh to improve the overall fps performance, with blender source and infos. Up you go
My Rig:
P3D 1.7.0@WinXP & Kubuntu 10.04- Athlon 64 5200 X2 ~ Radeon 3200HD (integrated)
User avatar
astelix
 
Posts: 866
Joined: Mon Mar 27, 2006 4:36 pm
Location: Milano, ITA

Postby adr » Sat Feb 06, 2010 1:29 pm

Theres a bug in your code ^^; you have two commands for the same letter "w".
adr
 
Posts: 532
Joined: Wed Oct 12, 2005 8:26 pm
Location: USA

Postby astelix » Sat Feb 06, 2010 5:57 pm

of course was put on purpose, just to see if somebody was still interested to this thread :wink:

thankyou adr for the hint, now all should be OK
My Rig:
P3D 1.7.0@WinXP & Kubuntu 10.04- Athlon 64 5200 X2 ~ Radeon 3200HD (integrated)
User avatar
astelix
 
Posts: 866
Joined: Mon Mar 27, 2006 4:36 pm
Location: Milano, ITA

Postby adr » Sat Feb 06, 2010 6:21 pm

astelix you're doing a great job making this. I usally tell people to come here first if they have any problems with collision. They usally see what they did wrong and get it fix perty fast.

I think these examples should be added to some sorta "help pack" to show off what panda can do and how to do it.

Pluse, haven't you notice the number of "collision help questions" have gon down by a lot, lol?
adr
 
Posts: 532
Joined: Wed Oct 12, 2005 8:26 pm
Location: USA

Postby astelix » Sat Feb 06, 2010 6:43 pm

adr wrote:Pluse, haven't you notice the number of "collision help questions" have gon down by a lot, lol?

hah a huge step to decrease carbon emissions and keep the planet green! :)
OT: BTW I actually found a nice resource to monitor carbon emissions by country (not very up-to-date though)
My Rig:
P3D 1.7.0@WinXP & Kubuntu 10.04- Athlon 64 5200 X2 ~ Radeon 3200HD (integrated)
User avatar
astelix
 
Posts: 866
Joined: Mon Mar 27, 2006 4:36 pm
Location: Milano, ITA

Postby adr » Sat Feb 06, 2010 6:50 pm

Now add a small wall into step10 so I can see whats wrong with my collision and octrees:P
adr
 
Posts: 532
Joined: Wed Oct 12, 2005 8:26 pm
Location: USA

Postby astelix » Sat Feb 06, 2010 7:06 pm

indeed that is definitely on my to-do list but I guess would be the last step of the tutorial, where I'll put all the steps together to have a big scene with lotta things stuffed into. But before that I would make one or two steps talking about particle physics and another one about fluid collisions (kinda bullets showcase) so I guess we won't see that too soon.
My Rig:
P3D 1.7.0@WinXP & Kubuntu 10.04- Athlon 64 5200 X2 ~ Radeon 3200HD (integrated)
User avatar
astelix
 
Posts: 866
Joined: Mon Mar 27, 2006 4:36 pm
Location: Milano, ITA

Postby Ogga » Tue Feb 09, 2010 2:23 pm

Hi,

I eagerly went over the tutorial. Very well written. It helped me get a much better grasp of the Panda collision system.
After reading the 10 steps, I'm still having problems finding the right approach for the specific game I'm trying to write (a 2.5d platformer - the characters are 2d, and the platforms are 3d boxes).
Any suggestions as how to approach the collisions in such a game (I'm especially having a hard time figuring how to handle the "floors" - It seems I'll need to know the collision direction (for stopping/starting a fall and so forth)).

Thanks,
Ogga
Ogga
 
Posts: 26
Joined: Wed Dec 02, 2009 2:21 am

Postby astelix » Tue Feb 09, 2010 6:39 pm

Ogga wrote:Hi,...
I'm still having problems finding the right approach for the specific game I'm trying to write (a 2.5d platformer - the characters are 2d, and the platforms are 3d boxes).
Any suggestions as how to approach the collisions in such a game (I'm especially having a hard time figuring how to handle the "floors" - It seems I'll need to know the collision direction (for stopping/starting a fall and so forth)).

Thanks,
Ogga

hi Ogga welcome here.
For the info you provided above, the first thing I'll do will be to treat your 2.5d avatars as it was 3D, so i.e. you just switch what is now the smiley model in one of these steps with your flat avatar and keep parenting with 3D colliders. As simple as it sounds. So, try by yourself to modify step9 smiley with one of your characters and see if you are able to make it work, otherwise come back here with your code and we'll see together what is wrong.
My Rig:
P3D 1.7.0@WinXP & Kubuntu 10.04- Athlon 64 5200 X2 ~ Radeon 3200HD (integrated)
User avatar
astelix
 
Posts: 866
Joined: Mon Mar 27, 2006 4:36 pm
Location: Milano, ITA

Next

Return to Code Snippets

Who is online

Users browsing this forum: No registered users and 3 guests