Version: Unity 6.7 Beta (6000.7)
LanguageEnglish
  • C#

TransformWriteMode

enumeration

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Description

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; } }

Properties

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.