Packageflare.collisions
Classpublic class SphereCollision
InheritanceSphereCollision Inheritance Object

The SphereCollision class provides tools to detect the collisions of a sphere against polygonal objects.

Wraps 3d objects, such as characters, spheres or boxes, in a virtual sphere and uses this sphere to detect the other objects around it. With this class we can detect collisions against walls, floors, ceilings, specific areas, etc. At the same time, we can generate or not a response for them.

The slider method detects collisions and provides a sliding response according to the (normal) inclination of the collision.

The fixed method detects collisions and generates a static response, locating the colliding object exactly at the collision point.

The intersect method detects when the colliding object intersects another 3d mesh but does not generate any response.

Download example - 07 - sphere collision



Public Properties
 PropertyDefined By
  collided : Boolean
[read-only] Returns whether collision occurred or not in the last check.
SphereCollision
  collisionCount : int
[read-only] Returns the number of objects that will be checked.
SphereCollision
  collisionTime : int
[read-only] Returns the time taken to perform the last check in milliseconds.
SphereCollision
  data : Vector.<CollisionInfo>
CollisionInfo-type vector with collision results.
SphereCollision
  offset : Vector3D
Sets or returns the displacement of the colliding sphere center.
SphereCollision
  radius : Number
Sets ir returns the collision radius that will be used to detect collisions.
SphereCollision
  source : Pivot3D
[read-only] Returns the source used to test the collisions.
SphereCollision
Public Methods
 MethodDefined By
  
SphereCollision(source:Pivot3D, radius:Number = 1, offset:Vector3D = null)
Creates a new SphereCollision object.
SphereCollision
  
addCollisionWith(pivot:Pivot3D, includeChildren:Boolean = true):void
Adds objects that will be used to test collisions.
SphereCollision
  
fixed():Boolean
The fixed method detects collisions and generates a static response, locating the colliding object exactly at the collision point.
SphereCollision
  
intersect():Boolean
The intersect method detects when the colliding object intersects another 3d mesh but will not generate any response.
SphereCollision
  
removeCollisionWith(pivot:Pivot3D, includeChildren:Boolean = true):void
Removes a Pivot3D to stop its checking process.
SphereCollision
  
reset():void
The SphereCollision class calculates collisions based on object trajectory and previous position.
SphereCollision
  
slider(precision:int = 2):Boolean
The slider method detects collisions and provides a sliding response depending on the collision inclination (normal).
SphereCollision
Property Detail
collidedproperty
collided:Boolean  [read-only]

Returns whether collision occurred or not in the last check.


Implementation
    public function get collided():Boolean
collisionCountproperty 
collisionCount:int  [read-only]

Returns the number of objects that will be checked.


Implementation
    public function get collisionCount():int
collisionTimeproperty 
collisionTime:int  [read-only]

Returns the time taken to perform the last check in milliseconds.


Implementation
    public function get collisionTime():int
dataproperty 
public var data:Vector.<CollisionInfo>

CollisionInfo-type vector with collision results.

offsetproperty 
offset:Vector3D

Sets or returns the displacement of the colliding sphere center.


Implementation
    public function get offset():Vector3D
    public function set offset(value:Vector3D):void
radiusproperty 
radius:Number

Sets ir returns the collision radius that will be used to detect collisions.


Implementation
    public function get radius():Number
    public function set radius(value:Number):void
sourceproperty 
source:Pivot3D  [read-only]

Returns the source used to test the collisions.


Implementation
    public function get source():Pivot3D
Constructor Detail
SphereCollision()Constructor
public function SphereCollision(source:Pivot3D, radius:Number = 1, offset:Vector3D = null)

Creates a new SphereCollision object.

Parameters
source:Pivot3D — Pivot that will serve as colliding object. It could be a character, a camera, etc.
 
radius:Number (default = 1) — Collision radius that will be used to detect collisions.
 
offset:Vector3D (default = null) — By default, the virtual sphere center will be placed at the origin of the Pivot3D that is used as source, i.e. at the (0,0,0) point. The offset parameter allows the user to move the sphere center to a more convenient position manually if necessary. The offset parameter must be represented in the object’s local space; therefore, if the 'source' object is rotated, the offset will also be rotated.
Method Detail
addCollisionWith()method
public function addCollisionWith(pivot:Pivot3D, includeChildren:Boolean = true):void

Adds objects that will be used to test collisions.

Parameters

pivot:Pivot3D — Pivot3D object to be checked for collisions.
 
includeChildren:Boolean (default = true) — defines whether Pivot3D children are to be included.

fixed()method 
public function fixed():Boolean

The fixed method detects collisions and generates a static response, locating the colliding object exactly at the collision point. When this method is used, the object will stop at the first collision it encounters and will remain in that position without sliding, which is typical of the slider method.

Returns
Booleantrue if collision occurred.
intersect()method 
public function intersect():Boolean

The intersect method detects when the colliding object intersects another 3d mesh but will not generate any response. It can be used to detect collisions with invisible zones, for example.

Returns
Booleantrue si hubo colisión.
removeCollisionWith()method 
public function removeCollisionWith(pivot:Pivot3D, includeChildren:Boolean = true):void

Removes a Pivot3D to stop its checking process.

Parameters

pivot:Pivot3D — Pivot3D object to be removed.
 
includeChildren:Boolean (default = true) — defines whether Pivot3D children are to be removed.

reset()method 
public function reset():void

The SphereCollision class calculates collisions based on object trajectory and previous position. In some cases, when the source object is to be removed and forced to a given position, collisions should be reset. The reset method must be used after repositioning the object.

slider()method 
public function slider(precision:int = 2):Boolean

The slider method detects collisions and provides a sliding response depending on the collision inclination (normal).

Parameters

precision:int (default = 2)

Returns
Booleantrue if collision occured.