New Bullet Character Controller

Return to Panda Features in Development

New Bullet Character Controller

Postby coppertop » Sat Jun 16, 2012 3:06 pm

Hello,

This is a Bullet port of my ODE Character Controller, with some additional improvements made possible by Bullet's awesomeness. It is aimed to replace the Bullet's default KCC in Panda, because that code has lots of missing features and some bugs. Hopefully this one will be better ;).

IMPORTANT
You have to use a new development build of Panda and even there collision detection might not work. This is a problem with Bullet and enn0x is looking into it.

Features included:
  • Walking with penetration prevention
  • Jumping with active and passive jump limiter. Active means limiting the max jump height based on the distance to the "ceiling". Passive means falling automatically when a "ceiling" is hit.
  • Crouching with stand up limiter which prevents the character from standing up if inside a tunnel or other limited space
  • Slope limiter of arbitrary maximum slope values which may or may not affect the movement speed on slopes smaller than maximum
  • Stepping, supports walking steps up and down (prevents "floating" effect)
  • Flying support for no-clip, ladders, swimming or simply flying
  • Simplified state system. Makes double/multiple jumps impossible by default (and you can easily change that if you want to)
  • Callbacks for landing and standing up from crouch
The controller is composed of a levitating capsule (allowing stepping), a kinematic body and numerous raycasts accounting for levitation and spacial awareness.

The code is documented, so take a look into kcc.py. Note it is not integrated yet and doesn't inherit from Node.

If you want to parent anything to the controller, you will have to use the movementParent node. It is now exposed.

demo.py is obviously the demo and mouseLook.py is the custom mouselook code used for TPP camera in the demo. I'm not sure if the demo code will work correctly on Windows because of the differences in mouse support, so let me know if it doesn't. If you end up with the camera under the map, don't worry this is not a bug, it's just an orbit code, not real TPP -- just move the mouse until correct orientation is restored.

The jump height is deliberately insane in order to better visualize the active jump limiter.

Demo controls:
  • WASD -- as usual
  • space -- jump
  • c -- crouch
  • shift -- run
  • control -- toggle flight
  • r, f -- fly up, down

And finally, you can get it here:
https://github.com/peterpodgorski/panda3d-bullet-kcc

Enjoy and please give feedback
Last edited by coppertop on Wed Jul 11, 2012 4:29 am, edited 2 times in total.
User avatar
coppertop
 
Posts: 527
Joined: Sat Apr 18, 2009 5:48 am

Postby wolf » Sat Jun 16, 2012 5:04 pm

Really great work you have done here. It is really useful.

But one question I have about the demo and the "flying" support. As it looks in the demo, the r and f key should apply some flying. But if I press them, the character doesn't do much. It just moves a few pixels up and down. Did I understand this wrong in the Demo, or how would one use the Flying support for for example ladders?
wolf
 
Posts: 24
Joined: Sat Jun 27, 2009 2:07 am
Location: Germany

Postby coppertop » Sat Jun 16, 2012 5:14 pm

I just forgot to include a proper presentation of flying into the demo. The r and f keys do make the controller fly(yyyy like an eagle... sorry, couldn't help myself), but there's no binding for switching movementState to "flying". And that's required for r and f to work. I will include that tomorrow, and for now you can just add:
Code: Select all
self.character.movementState = 'flying'

at the end of the setup() method, which will permanently enable flying, just so you can try it out.

That also reminds me a setMovementState method would be nice.

To make a ladder (or a force field, water etc.), you would simply use an area trigger (made of a bullet ghost object) which would set movementState to 'flying' on every character entering it, and 'falling' on every character leaving it.
User avatar
coppertop
 
Posts: 527
Joined: Sat Apr 18, 2009 5:48 am

Postby Nemesis#13 » Sun Jun 17, 2012 4:50 am

A very useful snippet. Thanks.
User avatar
Nemesis#13
 
Posts: 1041
Joined: Mon Aug 04, 2008 8:09 pm
Location: Germany

How to get the character controller into the scene graph

Postby zwillenguru » Sun Jun 17, 2012 9:12 am

Hi,
I just wrapped my head around your code. Its really impressive but I cant figure out how to get it included in my scene. I would like to reparent a 3d Model to the charactercontroller, so that its moved together with the controller. Unfortunately the charactercontroller itself is not a nodepath. In your code you sync the position of the physics capsule with the "movement parent". An intuitive choice would be to reparent my 3d object to the movement parent. But since its marked as private i figured there would be a better way. What did you intend as the "canonical" way to use the character controller. Im afraid the demo has solved my problem.

Thank you for your great code.
zwillenguru
 
Posts: 12
Joined: Mon Nov 21, 2011 10:21 am

Postby coppertop » Sun Jun 17, 2012 10:58 am

@zwillenguru

The code is work in progress so there is no "canonical" way to do anything yet ;D. The goal is to make it a node/nodepath so that you can use it just like anything else. I would like to have it integrated as deeply into Panda and Bullet as possible. This is not straight forward.

I will expose the movementParent, so that you can have something to parent to for now. Making it private right now was not the best decision.

EDIT:

Exposed the movement parent, added a fly switch and moved the files to github.
User avatar
coppertop
 
Posts: 527
Joined: Sat Apr 18, 2009 5:48 am

Postby zwillenguru » Mon Jun 18, 2012 12:43 pm

@coppertop
Thank you very much for your great code and the fast response. I really appreciate your help
zwillenguru
 
Posts: 12
Joined: Mon Nov 21, 2011 10:21 am

Postby enn0x » Tue Jul 10, 2012 8:07 am

sorry for the last response. This is really a great piece of code. I would not have thought that it is possible to write so much character functionality with so little lines of code. Congratulations.

About the "duplicate manifold points" problem, well, I don't have much more insight than three weeks ago. It seems that this problem is gone when using Bullet 2.80. but I can not pin down the change in Bullet's source code which is responsible for the effect. I think we should upgrade the buildbot machines to Bullet 2.80.
enn0x
 
Posts: 1356
Joined: Wed Nov 08, 2006 1:39 am
Location: Germany, Munich

Postby wolf » Sun Jul 22, 2012 6:47 am

After a while playing around with the code, I found some things which don't work as expected. The things I've found are the following:

1. The setPos function doesn't set the characters position which as far as I know is caused by the __currentPos variable. As workaround I put an extra function in my copy of the code, which will set the __currentPos variable and the movementParent position to the position which is given to the function. Maybe there is a better way to do this but that one worked for me.

2. If the character collides with ghost nodes he is pushed back and don't walk through the ghost node. I've try to change collision masks and some other things but haven't found anything that worked. Maybe someone knows a way how i need to change the code so my character can walk through the ghost nodes.

3. Maybe a design error by my side, but when I want to check if a collision occurs and need to know if the one of the nodes is my character then as a workaround i had to set up another function in the character controller class to check if the given node is self.__walkCapsuleNP.node().
wolf
 
Posts: 24
Joined: Sat Jun 27, 2009 2:07 am
Location: Germany

Postby coppertop » Sun Jul 22, 2012 2:28 pm

Thanks for the report, Wolf. I'll look into it as soon as I can.

Private variables might be a problem, I expected that. As I said, the plan was to make it a Node, but I'm not sure if that's what the plan still is. For now, you can even remove __ from all collider variables and use them directly. It won't hurt and I might expose them like that myself, just make everyone's lives a bit easier.

Regarding the bug #2, it's very much possible. I haven't yet checked the controller's behavior with triggers (although I probably should have) so it might not take this case into consideration. There is a special case needed for that, when the KCC will acknowledge the contact, but won't react to it. This should be easy to fix.

Once again, thanks for the info.
User avatar
coppertop
 
Posts: 527
Joined: Sat Apr 18, 2009 5:48 am

Postby coppertop » Tue Jul 31, 2012 6:52 am

Sorry I took so long, I had no time to get to this earlier.

I have committed the requested changes. Now setPos should work correctly, along with setX, setY and setZ.

The self.capsule and self.capsueNP variables are no longer private so you can use them to check if the colliding object is the KCC. Note that you should use these variables and not walkCapsule or crouchCapsule, which are still private. This is because capsule and capsuleNP are state independent.

I've also fixed the Ghost collision behavior.
User avatar
coppertop
 
Posts: 527
Joined: Sat Apr 18, 2009 5:48 am

Postby wolf » Wed Aug 01, 2012 4:04 pm

Thank you, I've just updated my code and now everything works fine. Position is set correctly and ghost collision behavior is OK too. And also thanks for the hint with the collision detection over the capsuleNP variable.
wolf
 
Posts: 24
Joined: Sat Jun 27, 2009 2:07 am
Location: Germany

Postby coppertop » Wed Aug 01, 2012 4:09 pm

Thanks for the feedback, I'm very happy the code works fine now.
User avatar
coppertop
 
Posts: 527
Joined: Sat Apr 18, 2009 5:48 am

Foot Rays

Postby Pataua101 » Thu Aug 23, 2012 9:36 am

The Foot ray is still colliding with the top of ghost body's,i tried to fix it myself but for some reason ray testing is returning blanks about 80% of the time.
Just letting ya know.
User avatar
Pataua101
 
Posts: 35
Joined: Mon May 14, 2012 10:50 pm
Location: Auckland,NZ

Postby coppertop » Thu Aug 23, 2012 11:33 am

Ah, right, forgot to take change that. Frankly, I'm not actually using the KCC at this time (busy with other things) so you must excuse this kind of otherwise obvious bugs :). Stay tuned, I'll fix it ASAP.

EDIT:
It should now work correctly. Thanks for reporting :).
User avatar
coppertop
 
Posts: 527
Joined: Sat Apr 18, 2009 5:48 am

Postby wolf » Sat Oct 13, 2012 8:00 am

There is now another problem with the foot ray and ghost objects. If the foot ray hit a ghost object, while the character stand on the ground, the foot ray won't collide with the floor collision mesh. So the character falls through the ground until the body capsule hits the ground collision.
wolf
 
Posts: 24
Joined: Sat Jun 27, 2009 2:07 am
Location: Germany

Postby coppertop » Fri Oct 19, 2012 12:01 pm

Sorry for the lag, I forgot to enable watching this topic. The newest commit should fix the problem.
User avatar
coppertop
 
Posts: 527
Joined: Sat Apr 18, 2009 5:48 am

Postby wolf » Sat Oct 20, 2012 8:40 am

I just updated to the newest version and it looks good now. Thank you for fixing that problem.
wolf
 
Posts: 24
Joined: Sat Jun 27, 2009 2:07 am
Location: Germany

Postby coool » Thu Nov 08, 2012 12:16 am

nice posts..............
MichaelJeee
coool
 
Posts: 2
Joined: Thu Nov 08, 2012 12:10 am
Location: fsdf

Postby Tazaar » Tue Jan 29, 2013 1:41 pm

Found a fix for a tiny unimportant bug :)

in KCC function startCrouch on line 114 add line
Code: Select all
if self.isCrouching == False:


Or you will get this if trying to crouch while chrouching:
Code: Select all
:bullet(warning): rigid body not attached

:bullet(warning): rigid body already attached
Tazaar
 
Posts: 16
Joined: Sun Jan 27, 2013 10:56 am
Location: Sweden

Re: New Bullet Character Controller

Postby Pataua101 » Sun Apr 14, 2013 12:53 am

What license is this under?
I ported it to c++ because that is the way i use panda is this okay?

Thanks
User avatar
Pataua101
 
Posts: 35
Joined: Mon May 14, 2012 10:50 pm
Location: Auckland,NZ

Re: New Bullet Character Controller

Postby coppertop » Sun Apr 14, 2013 6:22 am

Sure, it's ok.
User avatar
coppertop
 
Posts: 527
Joined: Sat Apr 18, 2009 5:48 am

Re: New Bullet Character Controller

Postby Cahim » Fri Jun 07, 2013 2:58 pm

This is great, but I would like to know the licence the code is under as well. I heard the implicit "default licence" is rather restrictive.

Also, is it sensible to use the controller with PandAI pathfinding?

Anyhow, thank you for sharing it.
Cahim
 
Posts: 2
Joined: Fri Jun 07, 2013 1:44 pm

Re: New Bullet Character Controller

Postby coppertop » Fri Jun 07, 2013 3:30 pm

Basically do what you want with it (just don't claim you wrote it, because that wouldn't be nice of you ;) ).

I don't think it would work with PandAI and, to be honest, I consider PandAI way too limited for any real use.
User avatar
coppertop
 
Posts: 527
Joined: Sat Apr 18, 2009 5:48 am

Re: New Bullet Character Controller

Postby jonyfries » Sun Jul 07, 2013 8:46 pm

So I'm not sure if this is a bug or if I'm doing something wrong but when I try to use the fall callback I get the following error:

Code: Select all
  File "C:\Users\jonyfries\PycharmProjects\Bullet\gameObject\kcc.py", line 275, in __processFalling
    self.__fallCallback(self.__fallStartPos, *self.__fallCallback[1], **self.__fallCallback[2])
TypeError: 'list' object is not callable


I'm assuming that the call should be:

Code: Select all
self.__fallCallback[0](self.__fallStartPos, *self.__fallCallback[1], **self.__fallCallback[2])


Thanks for class! I love it and it is working very well for me so far. :) Of course I'm exactly 2 days into learning Panda3D...
jonyfries
 
Posts: 14
Joined: Fri May 01, 2009 2:31 pm
Location: Glenwood Springs, CO

Re: New Bullet Character Controller

Postby goosejon » Thu Feb 27, 2014 11:06 pm

I can't find a license anywhere. What's the license for this?
goosejon
 
Posts: 5
Joined: Mon Jan 27, 2014 9:48 pm


Return to Panda Features in Development

Who is online

Users browsing this forum: No registered users and 0 guests