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

PhysicsWorld.transformPlane

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

public TransformPlane transformPlane;

Description

Controls the transform plane that the world uses when writing transforms. See PhysicsWorld.transformWriteMode.

Set this property to run 2D physics in 3D space, for example to lay a 2D world flat on the ground.

 using Unity.Collections;
 using UnityEngine;
 using Unity.U2D.Physics;

public class CreateXZPlane : MonoBehaviour { public PhysicsWorld world;

private void Start() { // Create a world with a transform plane of XZ, which is the floor in 3D space. PhysicsWorldDefinition worldProperties = new PhysicsWorldDefinition { transformPlane = PhysicsWorld.TransformPlane.XZ, gravity = Vector2.zero }; world = PhysicsWorld.Create(worldProperties);

// Create a square boundary. PhysicsBody boundary = world.CreateBody(); using NativeList<Vector2> extentPoints = new NativeList<Vector2>(Allocator.Temp) { new(-4f, 4f), new(4f, 4f), new(4f, -4f), new(-4f, -4f) }; ChainGeometry boundaryWalls = new ChainGeometry(extentPoints.AsArray()); boundary.CreateChain(boundaryWalls, PhysicsChainDefinition.defaultDefinition);

// Create a body and set it moving. PhysicsBodyDefinition bodyDefinition = new PhysicsBodyDefinition(); bodyDefinition.type = PhysicsBody.BodyType.Dynamic; bodyDefinition.linearVelocity = new Vector2(7.3f, 5.7f); bodyDefinition.angularVelocity = 0f; PhysicsBody body = world.CreateBody(bodyDefinition);

// Add a shape with a bouncy material. body.transformObject = transform; PhysicsShapeDefinition shapeDefinition = new PhysicsShapeDefinition(); shapeDefinition.surfaceMaterial = new PhysicsShape.SurfaceMaterial { bounciness = 1f, friction = 0f }; body.CreateShape(new CircleGeometry { radius = 1f }, shapeDefinition); }

private void OnDisable() { world.Destroy(); } }