Package | flare.physics |
Class | public class Physics |
Inheritance | Physics ![]() |
See also
Property | Defined By | ||
---|---|---|---|
allowOverlaping : Number = 0.2 [static]
Defines the amount of overlaping allowed between objects. | Physics | ||
axis : int
Gets or sets the default axis vector for the broad phase. | Physics | ||
colliders : Vector.<Collider>
The collection of colliders. | Physics | ||
contacts : Vector.<Contact> [read-only]
Gets a reference to the contacts vector resulted in the last step() call. | Physics | ||
gravity : Vector3D
The default gravity vector. | Physics | ||
numContacts : int [read-only]
Gets the number of contacts resulted in the last step() call. | Physics | ||
sleepingOverlap : Number = 0.02 [static]
A value which defines a tolerance for sleeping objects to overlap before wake up. | Physics |
Method | Defined By | ||
---|---|---|---|
Physics()
Creates a new physics manager. | Physics | ||
Adds a new collider to the simulation. | Physics | ||
debug(contacts:Boolean = true, aabb:Boolean = true, count:int = -1):void | Physics | ||
Test a ray against a specific collider. | Physics | ||
removeCollider(collider:Collider):void
Remvoes a collider from the physics engine. | Physics | ||
step(iterations:int = 3, timeStep:Number):void
Performs one step of the physics simulation. | Physics | ||
Test collisions between two colliders. | Physics |
Constant | Defined By | ||
---|---|---|---|
MAX_COLLIDERS : uint = 65536 [static] | Physics | ||
MAX_CONTACTS : uint = 65536 [static] | Physics |
allowOverlaping | property |
public static var allowOverlaping:Number = 0.2
Defines the amount of overlaping allowed between objects. Greater values results in more stable simulations, but causes the objects to overlap more. This value is completelly dependent of the scale units your are working. Adjust it if necessary.
axis | property |
axis:int
Gets or sets the default axis vector for the broad phase. A value of -1 means the axis will be automatically adjusted, while this could cause performance issue when changing the axis. A value o 0 corresponds to the X-Axis, 1 to Y-Axis, and 2 to Z-Axis. Set this property to uase the longest axis in yout scene, for example Y-Axis for a vertical game or X-Axis for a side scroller game.
public function get axis():int
public function set axis(value:int):void
colliders | property |
public var colliders:Vector.<Collider>
The collection of colliders. this is only for reference, do not change this vector.
contacts | property |
contacts:Vector.<Contact>
[read-only] Gets a reference to the contacts vector resulted in the last step() call. Because contacts are getting reused on every step() call, the length of the vector could be anything from 0 to MAX_CONTACTS. To get the correct number of contacts use numContacts property.
public function get contacts():Vector.<Contact>
See also
gravity | property |
public var gravity:Vector3D
The default gravity vector. Colliders receive this refernce when added to the physics manager. You can set a different gravity vector for each collider if needed.
See also
numContacts | property |
numContacts:int
[read-only] Gets the number of contacts resulted in the last step() call.
public function get numContacts():int
See also
sleepingOverlap | property |
public static var sleepingOverlap:Number = 0.02
A value which defines a tolerance for sleeping objects to overlap before wake up. Small values works fine in most of the cases. When dealing with a lot of objects stacked randomly together, try increasing this value to get them to enter in sleeping mode more easily.
Physics | () | Constructor |
public function Physics()
Creates a new physics manager. By default one is created with each Scene3D, but you can create and manage your own instances for specific pourposes.
See also
addCollider | () | method |
public function addCollider(collider:Collider):Collider
Adds a new collider to the simulation. If the collider is set to a Pivot3D, there is no need to add the collider manually to the physics engine.
Parameters
collider:Collider |
Collider — The added collider or null if the collider was already added.
|
See also
debug | () | method |
public function debug(contacts:Boolean = true, aabb:Boolean = true, count:int = -1):void
Parameters
contacts:Boolean (default = true )
| |
aabb:Boolean (default = true )
| |
count:int (default = -1 )
|
rayCast | () | method |
public function rayCast(pos:Vector3D, dir:Vector3D, target:Collider, maxDistance:Number = 1000):Contact
Test a ray against a specific collider. This method ignores possible states like sleeping, triggers, or disabled colliders.
Parameters
pos:Vector3D — The source position of thr ray.
| |
dir:Vector3D — The normalized direction of the ray.
| |
target:Collider — The target collider to test against.
| |
maxDistance:Number (default = 1000 ) — The ray maximum distance.
|
Contact — The result contact if any,
|
See also
removeCollider | () | method |
public function removeCollider(collider:Collider):void
Remvoes a collider from the physics engine. If the collider is removed from a Pivot3D, there is no need to remove the collider manually from the physics engine.
Parameters
collider:Collider — The target collider to remove.
|
See also
step | () | method |
public function step(iterations:int = 3, timeStep:Number):void
Performs one step of the physics simulation. This method should be called inside the update event of the scene or enterFrame event to update the physics simulation.
Parameters
iterations:int (default = 3 ) — The number of iterations for the solver to perform. Higher values results in more aacurate and stable simulations but are more CPU expensives.
A value of 0, results in a detection phase only and no response to collisions is generated. | |
timeStep:Number (default = NaN ) — The inverse delta time for each step. Higher values results slower but more stable simulations. By default is set to 1 / 30.
|
test | () | method |
public function test(c0:Collider, c1:Collider, contactCount:int = 0):int
Test collisions between two colliders. This method checks for collisions even if the colliders are not included in the same collision group and ignoring other possible states like sleeping, triggers, or disabled colliders. The result contacts are stored in the contacts property.
Parameters
c0:Collider — First collider.
| |
c1:Collider — Second collider.
| |
contactCount:int (default = 0 ) — The index in the contacs vector where the result contacts will be placed.
|
int — The last contact index if any.
|
See also
var count:int = 0; count = physics.test( colliderA, colliderB, count ); count = physics.test( colliderA, colliderC, count ); count = physics.test( colliderA, colliderD, count ); if ( count > 0 ) { for ( var i:int = 0; i < count; i++ ) { var contact:Contact = physics.contacts[i]; } }
MAX_COLLIDERS | Constant |
public static const MAX_COLLIDERS:uint = 65536
MAX_CONTACTS | Constant |
public static const MAX_CONTACTS:uint = 65536
package { import flare.basic.*; import flare.physics.colliders.*; import flare.primitives.*; import flash.display.*; import flash.events.*; public class PhysicsTest extends Sprite { private var scene:Scene3D; public function PhysicsTest() { scene = new Viewer3D( this, "", 0.2 ); scene.addEventListener( Scene3D.UPDATE_EVENT, updateEvent ); scene.camera.setPosition( 20, 40, -60 ); scene.camera.lookAt( 0, 0, 0 ); var floor:Cube = new Cube( "floor", 100, 5, 100 ); floor.collider = new BoxCollider( 100, 5, 100 ); floor.collider.isStatic = true; var cube:Cube = new Cube( "cube" ); cube.collider = new BoxCollider( 10, 10, 10 ); cube.collider.isRigidBody = true; cube.setPosition( 0, 30, 0 ); cube.rotateZ( 23 ); scene.addChild( floor ); scene.addChild( cube ); } private function updateEvent(e:Event):void { scene.physics.step(); } } }