UDN
Search public documentation:

PhysXReference

한국어

Interested in the Unreal Engine?
Visit the Unreal Technology site.

Looking for jobs and company info?
Check out the Epic games site.

Contact the UDN Staff

UE3 Home > Physics > PhysX Reference

# PhysX Reference

## Force fields

### Common parameters to all force fields

• bForceActive - Indicates whether the force is active at the moment.
• ForceFieldChannel - Identifies which force field exclude volumes (RB_ForceFieldExcludeVolumes) apply to this force field.
• bForceApplyToCloth - Enable/Disable influence on cloth.
• bForceApplyToFluid - Enable/Disable influence on fluid particles.
• bForceApplyToRigidBodies - Enable/Disable influence on rigid bodies.
• bForceApplyToProjectiles - Enable/Disable influence on projectiles like rockets.
• CollideWithChannelsIdentifies - Which types of objects are influence by this force field.

The force field is represented as a sphere. Objects inside the sphere will be applied a radial force.

• ForceStrength - Strength of the force applied by this actor. Positive forces are applied outwards.
• SwirlStrength - This field is not used. (How strongly objects orbit around Z axis of actor.)
• SpinTorque - This field is not used. (How strongly to spin objects around their local Z.)
• ForceFalloff - The way in which the force falls off as objects are further away from the location. Either the applied force is constant independent of the position, or the force gets linearly interpolated from ForceStrength at the center to zero at a radius of ForceRadius.
• RadialForceMode - Indicates which type of force mode is used.

### RB_CylindricalForceActor

The force field is represented as a Cylinder. Objects inside the cylinder will be applied a radial, lift and rotational force depending on the defined parameters. The radial force is only applied if the Velocity of the object is smaller that the escape velocity and when the object is moving away from the center. This has been done to prevent objects from quickly leaving the force field.

• RadialStrength - Strength of the force applied outwards from the cylinder axis.
• RotationalStrength - Rotational strength of the force applied around the cylinder axis.
• LiftStrength - Strength of the force applied along the cylinder axis
• LiftFalloffHeight - Lift falloff height, 0-1, lift starts to fall off in a linear way above this height.
• EscapeVelocity - Velocity above which the radial force is ignored.
• ForceRadius - Radius of influence of the force at the bottom of the cylinder.
• ForceHeight - Height of force cylinder.
• HeightOffset - Offset from the actor base to the center of the force field.

Further information can be found in these documents:

## Scene compartments

Allows user to separate objects into compartments which may or may not interact with one another. Compartments allow the parallelization of scenes which can simulate while the game engine is performing other tasks. In addition compartments can be individually configured to run at different sub steps or possibly interleaved simulations in order to improve performance on effects based scenes.

A compartment represents a sub-instance of one type of physics simulation, for example hardware fluid, hardware rigid body, or software rigid body. Several compartments may exist inside one scene, (including several of the same type) and interaction between them and the scene proper is taken care of automatically. This allows for transparent manipulation, simulation and interaction, without having to worry about the low-level nuts and bolts.

The SDK manages all links between the compartments. For example, when a material is created, it will be created for all rigid body compartments, or if a ray cast is performed, the query will return all intersected hardware and software objects in all compartments.

A newly created scene, hardware or software, contains no compartments. Any object that is added to the scene will be inserted into the scene proper, unless either a compartment is specified in its descriptor, or that type of object cannot exist directly in the scene.

The latter applies to the example fluid in a software scene. In such a case, an appropriate default compartment will be created for the new object if none exists already.

Here follows a comprehensive list of the different possibilities for creating objects with compartments, and what interactions they support. Interactions include both collisions between physical entities, and trigger testing.

### No PhysX hardware

#### No compartment specified:

Item Resides in Affects Affected by
Rigid bodies Scene proper Everything Each other, cloth with two-way interaction set (even in compartments), fluid with two-way interaction set (only in compartments)
Fluids Not available in software
Cloth Master scene Rigid bodies only in master scene, if two-way interaction is set Rigid bodies only in master scene.

#### Compartment specified:

Item Resides in Affects Affected by
Rigid bodies Specified compartment Each other only Each other, rigid bodies in master scene
Fluids Not available in software
Cloth Specified compartment Rigid bodies only in master scene, if two-way interaction is set Rigid bodies only in master scene.

### With PhysX hardware

#### No compartment specified:

Item Resides in Runs on Affects Affected by
Rigid bodies Scene proper By scene type Everything Each other, cloth with two-way interaction set (even in compartments), fluid with two-way interaction set (only in compartments)
Fluids Default fluid compartment (will create if nonexistent) Hardware Rigid bodies only in master scene, if two-way interaction is set Rigid bodies only in master scene.
HW Cloth1 Default cloth compartment (will create if nonexistent) Hardware Rigid bodies only in master scene, if two-way interaction is set Rigid bodies only in master scene.
SW Cloth1 Scene proper Software Rigid bodies only in master scene, if two-way interaction is set Rigid bodies only in master scene.

#### Compartment specified:

Item Resides in: Runs on: Affects: Affected by:
Rigid bodies Specified compartment As the compartment Each other only Each other, rigid bodies in master scene2
Fluids Specified compartment Hardware Rigid bodies only in master scene, if two-way interaction is set Rigid bodies only in master scene.
Cloth Specified compartment As the compartment Rigid bodies only in master scene, if two-way interaction is set Rigid bodies only in master scene.
2 Triggers in compartments do not react to bodies in the master scene)

### Default implementation

Currently UE3 creates four compartments in the NxScene. Pointers to these compartments, along with the NxScene, are stored in the level's FRBPhysScene. The compartment types created are:
• Rigid body
• Fluid
• Cloth
• Soft body
Note: This is not used at the moment, but it is here for future functionality.

To create a PhysX object within a compartment, you only need to pass in a pointer to the appropriate compartment in the objects' descriptor. For example, NxActorDesc contains a 'compartment' field. If this field is left NULL, then the object will be placed into the primary (normal) PhysX scene.

The UE3 class UPrimitiveComponent now has a bUseCompartment bool. This is interpreted appropriately for the different kinds of objects derived from this class. If the UPrimitiveComponent has a BodyInstance, then the NxActors created for that BodyInstance will be put into the rigid body compartment, if bUseCompartment is set.

For USkeletalMeshComponents, if a cloth simulation is specified, then the bUseCompartment flag will determine if the cloth is to be put into the cloth compartment.

Fluids are treated differently; in UE3 we always place the NxFluid into the fluid compartment.

## One way interaction ("Dominance Groups")

With dominance groups one can have all constraints (contacts and joints) created between actors act in one direction only. This is useful if you want to make sure that the movement of the rider of a vehicle or the pony tail of a character doesn't influence the object it is attached to, while keeping the motion of both inherently physical.

The dominance group is a property of the NxActor. It is simply a 5-bit (0-31 range) identifier. When a constraint (either joint or contact) acts between two actors, their dominance groups are used to determine which are influenced. The influence is determined by a user-defined matrix of pairs of reals. When two NxActors interact, their dominance group numbers are used to look up the correct real pair in the matrix. Each real may be in the range [0.0,1.0], and the value determines how much influence each NxActor receives from the interaction. Currently, only the values 0.0 and 1.0 are supported. The intermediate values may be used for "partial" interactions in the future.

By default, the interaction matrix is set up so that if the actors' dominance groups are equal, (1.0,1.0) is returned. This is the "normal" interaction behavior - both actors are influenced by the constraint. If the actors' dominance groups are not equal, then the default matrix will return (0.0,1.0) or (1.0,0.0) depending on which group ID is greater. It is set up so that the lower dominance group ID gets the 1.0 weight, while the higher group ID gets the 0.0 weight. That is, lower group IDs win. PhysX sets the default dominance group ID to 0, which will always win (or tie) with the default interaction matrix.

UE3 resets the NxActors' dominance group to 15 (by default), but does not modify the interaction matrix. This makes it easier to specify more- and less-dominant IDs. In UE3 the dominance group is specified by the RBDominanceGroup field in UPrimitiveComponent.

## PhysX visualization flags

There are several PhysX visualization flags which can be set on the command line by typing NXVIS followed by one of the following flags:

• Axes
• WORLDAXES - Visualize the world axes.
• BODYAXES - Visualize a body's axes.
• MASSAXES - Visualize a body's mass axes.
• Contacts
• CONTACTPOINT - Visualize contact points.
• CONTACTS - Visualize contact normals.
• CONTACTERROR - Visualize contact errors.
• CONTACTFORCE - Visualize contact forces.
• Joints
• JOINTLIMITS - Visualize joint limits.
• JOINTLOCALAXES - Visualize local joint axes.
• JOINTWORLDAXES - Visualize joint world axes.
• Collision
• CCD - Visualize CCD skeletons.
• CCDTESTS - Visualize CCD tests.
• COLLISIONAABBS - Visualize bounds (AABBs in world space).
• COLLISION - Visualize shape.
• Red - BSP/Trimesh/Heightfield
• Orange - Convex
• White - Sphere/Box Primitives
• COLLISIONAXES - Visualize shape axes.
• Cloth
• CLOTH_MESH - Visualize cloth meshes.
• CLOTH_COLLISIONS - Visualize cloth rigid body collision.
• CLOTH_ATTACHMENT - Visualize cloth attachments.
• CLOTH_SLEEP_VERTEX - Visualize cloth sleeping with full per-vertex information.
• CLOTH_SLEEP - Visualize cloth sleeping.
• Red - Sleeping
• White - Awake
• Blue - Static
• CLOTH_VALIDBOUNDS - Visualize cloth valid bounds.
• CLOTH_TEARABLE_VERTICES - Visualize tearable cloth vertices.
• Fluid
• FLUID_PACKETS - Visualize fluid packets.
• FLUID_POSITION - Visualize particle position.
• FLUID_MESH_PACKETS - Visualize available fluid mesh packets.
• FLUID_PACKET_DATA - Visualize fluid data packets.
• FLUID_BOUNDS - Visualize fluid AABB.
• FLUID_VELOCITY - Visualize particle velocity.
• FLUID_DRAINS - Visualize fluid drain shapes.
• FLUID_EMITTERS - Visualize emitter.
• Force Fields
• FORCEFIELDS - Visualize forcefield shapes.
• Softbody
• SOFTBODY_MESH - Visualize soft body meshes.
• SOFTBODY_ATTACHMENT - Visualize soft body attachments.
• SOFTBODY_COLLISIONS - Visualize soft body collisions with rigid bodies.
• SOFTBODY_SLEEP_VERTEX - Visualize soft body sleeping with full per-vertex information.
• SOFTBODY_SLEEP - Visualize soft body sleeping.
• SOFTBODY_VALIDBOUNDS - Visualize soft body valid bounds.

## Physics collision for rigid bodies

The way that PhysX rigid-body physics engine works is to generate contact points each frame for where things are touching. This is a more complicated process than performing a line check, so it is important to keep the geometry that real physics objects (such as a rag dolls) collide with as simple as possible, both for speed and behavior. For example, a lot of small triangles can lead to physics objects getting snagged, and will take a long time to process.

First, for an Actor to block physics Actors, it must have the bBlockRigidBody flag set to true. This is the default for static meshes and blocking volumes.

If UseSimpleRigidBodyCollision is true (see Collision Models above for more details), the engine will take the collision model and turn it into a set of convex hull primitives for contact generation. If you choose Collision from the View menu in the Static Mesh Editor, it will give you an overall primitive count. You ideally want to keep that count below 10, certainly under 100.

Rigid-body actors collide against BSP and terrain per-triangle. For this reason, you should make sure your BSP and terrain do not have very small triangles in them. For small details, use a blocking volume/collision model.

### Filtering rigid body collision

You can control which rigid body objects collide by using the RBChannel and RBCollidesWithChannel options within the Component.

• RBChannel - This indicates what type of object this is considered for collision.
• RBCollidesWithChannel - This indicates the types of object that should generate a collision with this one.

Things like BSP, Terrain and Static Meshes are in the Default channel, by default. So if you have a physics object that you want to collide with that, you need to make sure that Default is checked in the RBCollidesWithChannel. Normally static objects in a level will not have any flags set in RBCollidesWithChannel, so that dynamic objects 'choose' what they with to collide against.

There is a special channel RBCC_Nothing, which indicates nothing should by default collide with this object. However, you can still set entries in RBCollidesWithChannel. For example, if you want an object in the level to only collide with vehicles, you would set it to belong to the RBCC_Nothing channel, and then turn on the Vehicles flag in RBCollidesWithChannel.