A Minimal Collision-setup

after seeing so many people struggling with the collision system and got confused by the roaming ralph exaple.
i thought it might be time to finally throw in a “minimal example” which shows how to set up and use a collision ray to let it collide with the geometry of your choice.
no movement, no player placement nothing. just how to setup collision, and get the point where the collision appeared.

so there it is:
http://home.arcor.de/positiveelectron/files/project-files/collisionexample.zip

Very nice well documented example.

Perfectly shows the simplicity of Panda!

Ok Thomas… I’ve spent the past 7 hours TRYING to get my collision working. I’ve tried EVERY tutorial I could find. I just couldn’t get it to work.

I found your post and example here, and of course it works. I cut your code snippets and placed them in my code, and it did NOT work! The only thing different was the terrain file being used. So, I then changed my app to use your colltest.egg file for my terrain, and it works fine now!?!?!?!?!

Can you please explain to me what in the terrain file enables collisions to work? I know this is a newbie question, but I’ve given up figuring this out for myself. I build my terrain file using Blender, and it is nothing more than a grid mesh with a texture applied. What about this breaks collision detection?

7 hours… to learn it was my terrain file. I just might cry :frowning:

If I may interject a few questions before Thomas responds:

First of all, you say that you “changed your app” to use colltest.egg; how much did you change? If it was anything at all more than just changing the string that identifies your mesh to “colltest.egg” (along with whatever path information might be relevant), then try instating Thomas’ code, in particular the collide mask setting for the terrain.

Secondly, have you compared your egg file to colltest.egg, looking in particular for entries in one that are not in the other? They can be long files, but you should be able to skip a lot if you’re careful, since the majority of it should just be items of much the same form.

If I may interject a few questions before Thomas responds:

First of all, you say that you “changed your app” to use colltest.egg; how much did you change? If it was anything at all more than just changing the string that identifies your mesh to “colltest.egg” (along with whatever path information might be relevant), then try instating Thomas’ code, in particular the collide mask setting for the terrain.

Secondly, have you compared your egg file to colltest.egg, looking in particular for entries in one that are not in the other? They can be long files, but you should be able to skip a lot if you’re careful, since the majority of it should just be items of much the same form.

well i’m no collision expert either.
usualy one would use the tags “keep polyset descent” in the egg file to get more optimized collisions.
this example here just shows how to use geometry which does not contain any special collision stuff to get collisions working. so… i dont really know whats wrong with your file.

collision system definetly needs better documentation.

I changed my app by stripping out the old collision stuff I was trying to get working and inserting Thomas’ code. When the rays are drawn I can clearly see the collision in Thomas’s colltest.egg file, but when using my terrain file it does not produce a collision.

The differences in the two EGG files are these (see below code snippets):

colltest.egg uses " Mesh", and my terrain file uses " Grid".

colltest.egg contains tags, but my terrain.egg file does not (I’m not sure what option in Blender produces them).

I also manually added the " { Polyset keep descend }" tag to the terrain.egg file, but the colltest.egg file didn’t use it.

I’m not asking for you to tell me whats wrong with my file, I’m just trying to understand what is a EGG file would cause collision detection from failing.

colltest.egg:
{ Z-up }

{ “Egg laid by Chicken for Blender v1.0” }

Material.001 {
diffr {0.800000011921}
diffg {0.800000011921}
diffb {0.800000011921}
specr {0.0}
specg {0.0}
specb {0.0}
shininess {12.5}
}
Mesh {
Mesh {
0 {
3.907786 1.513235 -7.461235
{ 0.000000 0.000000 }
{ 0.333269 0.599488 0.727699 }
{ 0.56862745098 0.564705882353 0.564705882353 1.0 }
}

terrain.egg:
{ Z-up }

{ “Egg laid by Chicken for Blender vR44” }

Material.001 {
diffr {0.800000011921}
diffg {0.800000011921}
diffb {0.800000011921}
specr {0.25}
specg {0.25}
specb {0.25}
shininess {12.5}
}
Grid {
{ Polyset keep descend }
{
{
21.903385 0.000000 0.000000 0.000000
0.000000 21.903385 0.000000 0.000000
0.000000 0.000000 21.903385 0.000000
-0.319751 -0.590310 0.000000 1.000000
}
}

I found the issue. Not sure if this is “normal”, a bug, or just my inexperience, but if you set up your terrain in Blender using a “Mesh Grid” collisions will not be detected. I changed to a Mesh Plane, Mesh, Cube, and Mesh Circle all as tests and collisions work just fine in each of these.

Is there a reason behind Mesh Grid not working, or is this a bug?

Thanks,

Mike

Well, I typed up a long explanation of what the issue was and received an SMTP error trying to post the email… and lost it all.

Anyway, in short, I found the issue. If you create terrain in Blender using a Mesh Grid, collisions will not work. I changed to and tested terrain using Mesh Plane, Mesh Cube, and Mesh Circle and all of these work fine.

Is there a known issue with Mesh Grid, or is this a bug?

Thanks,

Mike

If anyone has this code I would be very happy if they are willing to share it with me, as the original file is now missing. :slight_smile:

whups. i’m sorry. i cleaned up my webspace a few weeks ago. apparently thought noone would be interested in it. gimme a few hours to find and re-upload it again :slight_smile:

ok… should be available again.

hehe thank you, no rush. Just when ever you have time :slight_smile:
Thanks again.

edit

Thank you very much, you had allready done it :slight_smile:

Hi there,

I just got this example (and it is a very good one, thanks). I altered so i could move the panda around and show a collision by pressing a key (ideally it should be a task but I’m just getting my feet wet).

It worked fine, but when I changed the collision solid from ray to a sphere, the collision stopped working! Can anyone shed some light on the matter, the collision detection on panda still baffles me :open_mouth: .

Thanks

unless you post your code noone will be able to tell you what’s wrong with it.
i would guess you are moving your sphere around but dont call collide() again.
it has to be called manually each frame.

The code is here:

http://www.4shared.com/file/140838104/2f3cc4d5/collisionexample2.html

It is weird because once I test a collision with nothing (i.e. go to empty space and test), it just stops detecting collisions.

Thanks for the help

uh… uuuh. don’t get me wrong… but your code really needs some cleanup.

first thing you shouldnt to is writing your own main-loop. instead of using while(True) taskMgr.step() you should set up a task which calls your functions every frame.

next thing are math operations. panda3d has a nodepath system which allows you to easily and efficiently manipulate objects.
rule of thumb: if you are using sin/cos/tan you’r doing something wrong.

player.setPos(player.getPos()+Point3(0.1*math.sin(angleradians),-0.1*math.cos(angleradians),0))

this line would convert into something as simple as

player.setX(player, 0.1 )

which moves the player along the x-axis relative to itself

now for the actual issue: once you leave the collision mesh it hangs itself.
first you do

for i in range(queue.getNumEntries())

followed by

colltrav.Traverse(render)

that means. if there where no collisions in the last frame (queue will still hold the old entries unless you call Traverse() again. then it will not call Traverse(), thus it will never ever update the queue.
moving colltrav.Traverse(render) above the .“for i in range…” line solves the issue.

Point taken, to much cut’n paste and not enough review, or planning for that matter.

I disagree (sort of) on this point. Although it is good that panda has this feature (by the way, thanks for telling me that), this method apparently uses the reference of the model, because it uses the side of the panda as front. I had to use setY() to make it work alright.

The way I did ignores the XY orientation because it takes relative angle as base. And basic math functions exist in every language, so it is a more generic way of thinking. But I have to give you that, in the context of panda3D it makes for cleaner code, and probably more efficient although I couldn’t tell from this example.

On second thought, it seems I’ve just explained why it’s a rule of thumb and not just a rule.

OOOh… Now everything makes sense! Thank you!

Thanks for the simple example.

Why do you do this?

player.reparentTo(terrain)

JB Skaggs

Sorry to resurrect such an old post, but I’ve been messing around learning Python/Blender/basic Panda and now I’m going over collision detection in Panda.

I have a few simple questions that I haven’t been able get around:

A. Can you edit the tags of an egg after it is exported (I’m using Blender)?

If so…
B.What do you open it with to edit it?

Edit: Of course after I post it, I figured out my problem. I was trying to open .egg.pz files…

Sorry :\

Alright, I’ve been busy with other life crap and I’ve finally gotten back to messing with Panda…

I read that I needed to use punzip to decompress .egg.pz files, but when I try to unzip the world.egg.pz file from the roaming ralph tutorial I get an error.

The ZIP file either contains errors or could not be found.

So apparently I did not figure out my problem.

I extracted punzip into my windows directory as per the install instructions and I used it to unzip a standard .zip file, but it will not unzip .pz’s.