Sign in to follow this  
zarfius

Character controller object pickup with PhysX

Recommended Posts

I'm implementing a character controller with all your typical first person behaviour. I've implemented walk (including stairs, etc) and jump without any trouble and to some degree pickup and throw. For the pickup code I've used a Fixed Joint and attached one end to the character controllers actor and the other end to the object actor. Then, when I rotate the player I manually rotate the controllers actor so that the object stays in front of the camera as if the player is holding the object (nothing special here, just think about how every other first person game works) The problem is that the character controller actor randomly stops rotating sometimes. After looking at the documentation it says that you should never change the properties of the controller's actor manually. So how am I supposed to ahieve this without doing that? The first thing I tried was creating another actor attached to the player's actor by another fixed joint and rotating that instead. The problem is that the extra actor's sole purpose is to get around the original issue. I don't need this extra actor to have a shape or body but I'm required to do so by PhysX. Surely there is a better way to acheive this typical behaviour of a first person character controller?

Share this post


Link to post
Share on other sites
Maybe promote the picked-up actor to KINETIC and move it along with the charakter manually? Haven't tried it, because I still fail to get a character controller with anything else than a vertical capsule :-) You probably need to deactivate collisions for that pair of controllers or your player bumps into his own cargo all the time.

Share this post


Link to post
Share on other sites
A kinematic actor is worth a shot. The main problem with that is the object might pass through walls when you push it into them. Depending on how small and close the object is to the player I might be able to get away with it though.

Also, I'll have to project the position of the object in front of the camera as the player turns but I figured I might have to that anyway with some of the idea's I already considered.

One idea is to use a kinematic actor and a joint to the object. The kinematic would simply move with the character controller.

Another option is to actually fix the character controller code supplied with PhysX since the full source is provided for it. I had a bit of a look today and it might take a while to track down the rotating issue, if ever.

I already had the issue with bumping into my own cargo, but that only happened if I was really close to the object when I picked it up. Easy enough to fix I'm sure.

Share this post


Link to post
Share on other sites
Well, I figured it out.

Turns out the actor was falling asleep during rotation when the player is standing still. When moving the actor automatically wakes up.

I'm not sure why setGlobalOrientationQuat doesn't wake up the actor esspecially since it says "This call wakes the actor if it is sleeping" in the documentation. Perhaps it's different for character controllers.

Either way, adding a manual wakeUp(1) call on the actor just before setting the orientation it seems to fix the problem.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this