PhysicsBody.TransformWriteMode
The method used to Write the body pose to the Transform. See _transformWriteMode.
Read time 1 minuteLast updated 10 days ago
Definition
- Type: Enum
- Namespace: Unity.U2D.Physics
- Assembly: UnityEngine.PhysicsCore2DModule
public enum PhysicsBody.TransformWriteMode
Remarks
By default, Unity writes the Transform component after it finishes calculating the physics simulation. Set this mode to or instead to interpolate positions between simulation steps. _transformObject is available only in a C# script, not in the Inspector window of a public PhysicsBodyDefinition object.
InterpolateExtrapolateExamples
// 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; }}
Fields
Value | Description |
|---|---|
| Current | The current body pose will be written to the Transform. |
| 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. |
| 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. |
| Off | This body pose won't be written to the Transform. |