The method used to Write the body pose to the Transform. See PhysicsWorld.transformWriteMode.
By default, Unity writes the Transform component after it finishes calculating the physics simulation. Set this mode to Interpolate or Extrapolate instead to interpolate positions between simulation steps.
PhysicsBody.transformObject is available only in a C# script, not in the Inspector window of a public PhysicsBodyDefinition object.
// Move a GameObject by creating a dynamic body and writing its Transform. using UnityEngine; using Unity.U2D.Physics;
public class MoveGameObject : MonoBehaviour { public PhysicsWorld world; public PhysicsWorldDefinition worldDefinition = PhysicsWorldDefinition.defaultDefinition;
void Awake() { // Enable physics bodies updating transforms. worldDefinition.transformWriteMode = PhysicsWorld.TransformWriteMode.Fast2D; world = PhysicsWorld.Create(worldDefinition); }
void Start() { // Create a body and shape. PhysicsBody circleBody = world.CreateBody(); CircleGeometry circleGeometry = new CircleGeometry { radius = 2f }; circleBody.CreateShape(circleGeometry);
// Set body to dynamic so it falls under gravity. circleBody.type = PhysicsBody.BodyType.Dynamic;
// Enable this physics body updating transforms. circleBody.transformWriteMode = PhysicsBody.TransformWriteMode.Current;
// Set the updated transform as the transform of this GameObject. circleBody.transformObject = transform; } }
| Property | Description |
|---|---|
| Current | The current body pose will be written to the Transform. |
| Interpolate | The interpolated pose from the previous body pose to the current body pose will be written to the Transform. The transform pose is essentially historic. |
| Extrapolate | The pose extrapolated from the current body pose to a future pose based upon the current linear/angular velocities will be written to the Transform. The transform pose is essentially predictive. |
| Off | This body pose won't be written to the Transform. |