[PHYSX] Know if an actor is linked to a character controller

Started by
3 comments, last by Alundra 9 years, 1 month ago

Hi,

I'm using the active transform to update all object of my scene linked to physx actors.

The problem is character controller never rotate (only if the up vector change) so I would only update translation for them.

A way exists to know if the physx actor is linked to a character controller, maybe a flag can be set on the actor ?

Here the code I use to update object of my scene :


// Get active transforms.
physx::PxU32 ActiveTransformCount;
const physx::PxActiveTransform* ActiveTransformArray = m_Scene->getActiveTransforms( ActiveTransformCount );

// Update each actor with the new transform.
for( physx::PxU32 i = 0; i < ActiveTransformCount; ++i )
{
  if( ActiveTransformArray[ i ].userData )
  {
    const physx::PxTransform& Transform = ActiveTransformArray[ i ].actor2World;
    IActor* Actor = static_cast< IActor* >( ActiveTransformArray[ i ].userData );
    Actor->SetTranslation( CVector3( Transform.p.x, Transform.p.y, Transform.p.z ) );
    Actor->SetRotation( CQuaternion( Transform.q.x, Transform.q.y, Transform.q.z, Transform.q.w ) );
  }
}

EDIT : Maybe the only solution is to set my object component as user-data of the physx actor and check the component type and update the owner of the component.

Advertisement

Im not sure if I understand the problem exactly. The transforms returned by active transform are for objects simulated by physx, for example boxes falling down a hill.

The character controllers are typically user/ai driven, so they get moved through the world not by the simulation but explicitly by using the controllers move() call to push the character controller through the world. After physx simulate() is finished the corrected position can be accessed through the controllers getPosition() call.

They cant be rotated through the controllers interface (that I know of) but the up axis can be set (a more recent feature) but that shouldnt prevent your character from rotating within the controllers capsule/box.

When you move the character controller using "move" it's then possible to update your object with the active transform.

Since I update all my objet linked to a physx actor using this way (active transform) I wanted to add the same for character controller since active transform is sent for it.

The only problem is on the code I do if I set the orientation that override orientation I have set in my actor of my 3D scene.

This is why I have to check if it's a character controller to only set the translation for them.

Other solution is to do a for loop to update all character controller after simulate maybe.

This solution avoid to do one if on each active transform.

An idea ?

Rechecking my own code I have my controllers user data flagged as controller, I skip them in active transform update and update them separately. This is because the character controller library is not directly part of the physx library, but built on top of it. The physx simulation doesnt recognize a controller object as manually driven, it just sees it as a regular kinematic, on top of that it currently ignores rotation. Also I believe an older version of physx use to have an explicit call in the controller manager for updating controllers after the simulation, which is why I did it that way, it was a fix for an upgrade change.

Id say handle it on its own in some way. Maybe a flag in your IActor like SkipRot() to avoid setting the rotation, or IsCtrler() and skip it altogether and do it somewhere else.

Ok yeah sounds like the only option. I will change the user data to store the pointer of the CharacterControllerComponent where he is created like that only translation will be applied there and the user will have to write code to handle rotation manually.

This topic is closed to new replies.

Advertisement