I am in a situation which requires me to adjust the orientation of my character controller on a regular basis. The controller seems to have no native support for any rotation or orientation, so my second approach was to recreate a new controller after the parent entity had changed its own orientation. This yields inconsistent results with the capsule collider, as it is sometimes recreated with the original orientation, and perpendicular to the characters actual orientation in the world. Is there any way for me to control this process?
The idea with the character controller in PhysX-3 is that the bounding box of the character remains vertical, but you adjust the orientation of your graphics character within that box. Are you trying to rotate the character’s orientation about a vertical axis, or about a horizontal axis? I’ll pass this question along to others.
Are you using PhysX 3.x?
If so, it’s
\brief Sets the ‘up’ direction.
\param[in] up The up direction for the controller. @see PxControllerDesc.upDirection */ virtual void setUpDirection(const PxVec3& up) =0;
I saw that almost 170 people looked inside this topic but only 2 people answered him.
I know that this is a really basic question - but it should get answered.
I really dont know why you want to rotate the PxShape from the PxController -
are you using a PxBoxController? If the edges are the problem then you could
rotate the PxShape - but if you want to rotate your mesh or what ever, you should
rotate really only the mesh, not the PxShape.
If you want to rotate the up-vector, then read what HaiLocLu wrote.
( Example: gravity changes when you walk on a planet -> Super Mario Galaxy )
But if you need to rotate the PxShape to the z axis ( mostly the “look” direction )
then you should try this code.
But before: I guess that the PxController dont have a direct way to rotate the PxShape because
there are optimizing algorithm due to the kinematic flag. So they dont let you rotate the PxShapes. But the PxController have inside a PxActor, which can be rotate. So you have to get the PxActor and get the PxShape from it.
Here is the code how you can do it:
PxBoxController* controller = static_cast<PxBoxController*> mPhysic->getManager()->createController(*mPhysic->getSDK(),mPhysic->getScene(),_controllerDesc); // create your PxBoxController with your own parameter // you also need your PhysXSDK and your PhysxScene pointers PxRigidDynamic* actor = controller->getActor(); // get the actor PxShape* shapes; // There is only one shape in this controller mActor->getShapes(shapes,1,0); // get that shape PxShape* shape = shapes; // Here is your shape
So with this code you created an controller and, of course, grabed the PxShape from it.
So all you have to do is to call inside your update method:
// You have to define a member variable or something else to store the pointer from shape! PxReal yawValue = [yourMeshOrientationHere] the values must be in radian shape->setLocalPose(PxTransform(PxQuat(yawValue,PxVec3(1,0,0)))); // turns the PxShape around yaw ( y axis )
So, you see thats all you need.
I hope I could help you and the other 160 guys :D
A super late response to this question, since we had resolved our issue some time ago, unfortunately it has shown up again, and causing more issues. So I will provide more details to more thoroughly explain the problem.
I am currently using PhysX 2.8.4, I realize this is not ideal, but the engine we use does not have up to date bindings for PhysX, and we dont have the time to change this ourselves, so we are making due.
The issue has to do with the orientation of the character controller, and the capsule itself. Our game supports the ability to “rotate the world” such that any of the major axis are supported as up, this happens dynamically at run time. After a character controller has been created, it seems to use information about the current scene (such as gravity) to optimize collision detection. There appears to be no way to change this after the controller is created, and it doesnt automatically update itself when the scene’s gravity is modified. Therefore, our current approach is to simply recreate the controller. This seems to work fine along the Y, and Z axis, but not along the X for whatever reason (by this i mean it is not aligning the controllers capsule along the gravity axis when using the X axis). We did identify that PhysX is very particular about normalized and axis aligned vectors, and we have ensured everything is perfectly axis aligned, alas still inconsistencies. I have attempted to rotate the hidden actor within the character controller, but unfortunately this appears to not affect the optimizations that are made to the controllers behavior.
The symptoms of this problem I had identified in another post which I will be cleaning up, but it comes down to collisions with triangle mesh geometry not registering when the capsule is created along the incorrect axis.