Force2D

From Unify Community Wiki
(Difference between revisions)
Jump to: navigation, search
(Description)
(Usage)
Line 4: Line 4:
  
 
==Usage==
 
==Usage==
 +
Assign this behavior to any GameObject.  Do not assign this to RigidBodies that are linked together with joints if you want to keep the physics engine more stable.
 +
 
==JavaScript - Force2D.js==
 
==JavaScript - Force2D.js==
 
  var depth = 0.0;
 
  var depth = 0.0;

Revision as of 18:46, 1 December 2005

Author: Jonathan Czeck (aarku)

Description

This script will allow you to constrain Unity's physics engine to two dimensions. It works best for rigidbodies that are not connected by physics joints.

Usage

Assign this behavior to any GameObject. Do not assign this to RigidBodies that are linked together with joints if you want to keep the physics engine more stable.

JavaScript - Force2D.js

var depth = 0.0;

function Awake()
{
	depth = transform.position.x;
}

function FixedUpdate ()
{
	transform.position.x = depth;
	fwd = transform.localRotation * Vector3.fwd;
	fwd.x = 0;
	transform.localRotation = Quaternion.LookRotation (fwd, -Vector3.Cross (Vector3.right, fwd));
}
Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox