[size=117]Be aware that this code is generally meant as internal and was extracted from a larger project I’m working on. This means I can’t ensure a stable API or regular updates.[/size]
The current version is 1.2.1, but you can still download the previous versions at the bottom of this post. I strongly discourage using versions earlier than 0.9 (actually, just use the most recent one, it’s the best one ).
Since version 1.2.0 the framework contains everything I wanted to release for now, so there will probably be only 1.2.x bug-fix releases from now on.
WARRNING: Panda 1.7.0 has a bug that causes it to leak memory when using this code. Please use it with newer snapshot builds or newer stable releases once such are available (1.7.1 and 1.7.2 are fine).
- World Manager, which makes it easier to use ODE with Panda and Python.,
- Basic classes for Static, Kinematic, Dynamic and Ray objects,
- Continuous Collision Detection support for fast moving small objects,
- Kinematic Character Controller (much more stable since 0.9),
- Player controller for FPP games using the KCC,
- Object picking and carrying for the player controller,
- Ray-based gun mechanics with support for automatic, semi-automatic and shotguns.
- Explosion mechanics and an example grenade implementation,
- Area Triggers,
- Map loading example,
- Moving platform example,
- Simple bit mask generator
- Visualization based on FenrirWolf’s code
If you want to read more about this framework, it’s features and limitations, please check this file:
Changes in 1.2.1:
- The Kinematic Character Controller now inherits from Kinematic Objects (by suggestion)
Changes in 1.2.0:
- Added support for moving kinematic platforms. Optionally dynamic objects can serve as moving platforms for the Character Controller as well, but not for other dynamic objects. Example included;
- Ability to easily change the size of the KCC with one intuitive method. Finally. Also the sample map was changed to correct scale;
- Correct bouncing and sliding in CCD-enabled dynamic objects. Their velocity is no longer artificially affected after collisions;
- Animation for smooth camera movement when going from standing to crouching and vice versa and while walking steps;
- Additional capsule for the KCC for better object pushing;
- Simple automatic BitMask generator;
- Uses FenrirWolf’s code for ODE visualizations. Thanks for writing and sharing it;
Changes in 1.0.1:
- Fixed shaking when the KCC collides with TriMesh geoms (although, I still not advice using trimeshes too extensively)
- Changed the advised bit mask setup in the sample
Changes between 1.0 and 0.9:
- Ditched the odeGeomData class – this made the code a lot cleaner, more optimized, and easier to use,
- Added support for firearms,
- Added example guns,
- Added rayObject class,
- Limited the use of in-place ray casting,
- Optimizations, bugfixes
Download the current version (1.2.1) here:
To see it in action run start.sh for Linux or start.bat for Windows. Or do python main.py.
Hope you’ll find it useful,
Looks like this would be a great addition to the tutorials. Care to make it more tutorial friendly?
control (crouch) seems to simply send the character flying upward for as long as I hold the button…but this is rather neat. Great Job. I second that this be turned into a sample program (it is almost there already!)
I’m getting this error when I run it:
ODE INTERNAL ERROR 1: assertion "Stride >= (int)sizeof(dContactGeom)" failed in dCollideBTL() [collision_trimesh_box.cpp]
I’m guessing you passed wrong arguments to OdeUtil.collide ?
This is a debug build of ODE, which probably explains why I’m getting the error and why you aren’t.
Thanks everyone for your interest and replies. I really appreciate it.
I guess I could. What exactly do you mean by “more tutorial friendly”? Except for making the map look less provisional. It’s the first time I put out a piece of code like that, so I’d really be thankful for more directions on this.
Crouch makes you fly? That’s strange… I’ve run the code here again, checked it and I see there is something wrong with crouching, but I don’t fly… You’re supposed to “fly” only when inside the ladder trigger. Can you tell me a little more about what exactly happens? Do you just take of and go up (up and away) higher and higher when control is pressed? Do I understand correct?
Yeah, that didn’t happen to me… I have the standard Panda 1.6.2 built from the Ubuntu package. I’d be very thankful though if you gave me a little direction on how to eliminate this problem - it’d be hard for me alone since I simply don’t get this error. Thanks very much in advance.
Yeah, when control is pressed you just continue moving at a constant velocity straight up, and upon releasing fall back down due to gravity–although it would appear that the camera moves down first for an instant (almost like one would expect when crouch is pressed). Simply tapping control gives a weird down up down bunny hop like thing.
This is really weird… and I cannot reproduce it :/. Crouching works as it should for me here (except that walking up stairs doesn’t work when crouching ATM). It also does for a friend I just asked to check it. Very strange…
Ok, time for a little update.
There’s a new map (still placeholders, but more obvious, the way I personally like them, dunno if you will too ).
Some bugs are fixed such as the player being unable to walk up steps when crouching. Also, now the KCC will correctly react to multiple collision contact points with the same object. I have also added a… chair. So you can sit and relax a little bit (I love Panda’s sequences, intervals and so on). I’m sure some more things were fixed but I can’t remember now… And I still haven’t been able to reproduce the “crouching-flying” error, so I’m very curious if it will happen again with this version.
There’s also more comments in the code files.
I guess that’s all.
The package is under the same link: dl.dropbox.com/u/196274/ODE_Cust … ork.tar.gz
Yea, I’ll look at the code, but I’m getting that couch error too. When you press it, you just go “fly” into the air as you hold the key down. I’m using a windows OS, so that may have to do with the problem maybe? Again, I’ll see what I can do.
Edit. Ok Not 100% sure, but you put 1.2 for self.crouchLevitation, so I changed it to .2 and then it seem to go down as normal, but when you hold on to it to long you’ll go thow the floor or the wall. This means it’s not locking after you press the key. I mean, it’s still going in the loops to go down. Maybe its gravity + couch, it says I hit the floor with a -5.
Hmm… I actually haven’t tested that on Windows, nor has anyone of my friends I sent it to, only on Linux. It would be very strange though if that was an OS-related problem, but who knows. I will have to test it there.
Adr, have you tried the new version? Is the bug still there? I haven’t made much of changes to the crouching code, but again, who knows.
Hmm… That gives me a clue on what’s wrong. The crouch levitation has to be a high value (though it does look like it’s too high at the first glance, but it’s not) because otherwise you won’t be able to climb stairs. Once I figure out what the flying deal is of course. Anyway, my guess is that instead of setting the levitation value it increases it in every step. That might be the case. I’ll dig into that, but first I must get into Windows and see if I get that glitch as well.
Yea thats with the new version. If you change that value, nothing else seems to get effected other then couch. It’s adding to the point where you skip a frame and go though something. Maybe you have something backwords? Like a If else statament. I’ll see what happens if I make it a -1.2
Edit. K, yea making it -1.2 works, but you still go thow a wall or the floor if you hold it to long. So something keeps adding to the value and you have something flip around inside.
It could be that windows keeps sending the ctrl command while that os only sends it onces?
Ok, checked it on Windows and fixed it. At least apparently, need confirmation. It seems like the problem was in fact OS-specific, in a way, but I think it’s more probable it was some difference between the Linux and Windows Panda built that was causing the glitch. I just don’t see how the system by itself could’ve caused it.
Anyway, the thing was that when crouching there was a collision between the footRay and the capsuleGeom. As a result the KCC thought you’re lower than levitation, and pushed you upwards. Hence the “we have lift-off to the International Space Station” thing. I’ve added an if to the ray collision callback to check if we’re not colliding with the capsule. I could’ve done that using masks, but that was quicker.
I’ve updated the package and it should work now.
Other then you can’t open the door while crouch and maybe naming the file testMapODE.py to just Main.py, it works great! I’m going to study it for my own game My collision and gravity sucks butt, but with your example I’ll get it working and I hope even faster then it has been.
Ok, another update than, into version 0.2.2.
Fixed the problem with not being able to use objects when crouching (or more precisely when holding control). And changed the name of the starter file to main.py .
dl.dropbox.com/u/196274/ODE_Cust … ork.tar.gz
finally found some time to test this.
it looks and feel great!
thank you very much for sharing
i hope this will become an official sample one day
Excellent! works great, and well commented.
Thanks for your opinions guys, I really appreciate them. Please tell me if there’s anything you’d like to see added there, not to mention if you find any bugs of course.
I have nothing against this code ending up as an official sample, I’m really all for that obviously . I just don’t know what I should do to get it there ATM, but it would be great.
Thanks again and enjoy.
I really like your work!
particularly, the way you implemented the world manager is very interesting!
Thank you very much for your work.
On a side note, I am trying to learn how to add new objects with physics, using your world manager…
I want to add a box (just the default panda3d box mesh provided with the SDK) and have it roll and react to the character, you get my point, some standard physics.
I am pretty sure I would use Dynamic instead of Kinematic, correct?
Here’s what I’ve done:
used self.worldManager.setGeomData(boxGeom, boxData)
and this works well, I can jump and hit into the box (I’ve placed it in the air)
However, it’s static. No matter what I’ve tried it refuses to fall due to gravity, or to react when I jump and hit into it.
How do I do this? I thought it’d be simple, but I suppose I’m missing something obvious
I’m glad you like it .
Yeah, perhaps I should have made an example of that in the package… Don’t know why I haven’t, so maybe I’ll update it with some boxes.
Anyway, yes, the box, or any other object that you want to be animated by ODE rather than by hand, should be Dynamic. But that’s the default setting when you look at setGeomData method.
It’s actually quite simple to do. You haven’t provided much information (a complete piece of code where you setup stuff would be very helpful next time), but I think I can see what’s wrong.
Instead of setGeomData(boxGeom, boxData) you should have used this:
self.worldManager.setGeomData(boxGeom, boxData, boxModel)
If you take a look into the odeWorldManager code you’ll see that this method takes 4 arguments: geom, data, object, kinematic. Geom is the OdeGeom, data is OdeGeomData and object is the visible 3D model. Kinematic is obviously a switch between kinematic and dynamic.
If you don’t add a value for the “object” argument the code will not crash however, since that’s the way you can add Static objects which are not animated in any way – neither by you nor by ODE. Objects such as walls (you can see setGeomData with None as object argument in main.py when I setup the static environment). In such objects the positions of graphical representation and collision body don’t need to be updated every frame since they do not change. But you need to remember about this, since if you forget the “object” argument you will end up with static objects by accident and no error to warn you (if you want such error you can modify the setGeomData() method to request the object argument and remember to set is to None for Statics).
Try this and let me know if it works.
Hi, and thank you for such a detailed reply!
Sorry about forgetting to post a snippet, I was tired… annd… well yes
I tired as you suggested however still no go, so here is my cube.py file, and I just plugged it into main.py (included with your example) by the following code:
box = loader.loadModel("box") #load model
box.reparentTo(render) #reparent to render
box.setPos(0, -7, 3) #set pos because I changed map
cube(self.worldManager, box) #make a cube (see cube.py)
that’s how its being called. and for the class:
def __init__(self, worldManager, model):
self.worldManager = worldManager
self.cubeNP = model
self.cubemesh = OdeTriMeshData(self.cubeNP, True)
self.cubeGeom = OdeTriMeshGeom(self.worldManager.space, self.cubemesh)
#self.cubeGeom = OdeBoxGeom(self.worldManager.space, 1, 1, 1)
self.cubeData = odeGeomData()
self.cubeData.name = "cube"
self.worldManager.setGeomData(self.cubeGeom, self.cubeData, self.cubeNP)
I’m still lookin’ to see where I’ve went wrong…
EDIT: fixed cube class (I forgot to change it back to TRI mesh)