Create a new CollisionComponent.
The ComponentSystem that created this Component.
The Entity that this Component is attached to.
The Entity that this Component is attached to.
The ComponentSystem used to create this Component.
The local space axis with which the capsule, cylinder or cone-shaped collision volume's length is aligned. 0 for X, 1 for Y and 2 for Z. Defaults to 1 (Y-axis).
Enable checking for duplicate vertices.
Whether the collision mesh should be treated as a convex hull. When false, the mesh can only
be used with a static body. When true, the mesh can be used with a static, dynamic or
kinematic body. Defaults to false
.
The total height of the capsule, cylinder or cone-shaped collision volume from tip to tip. Defaults to 2.
The radius of the sphere, capsule, cylinder or cone-shaped collision volumes. Defaults to 0.5.
The type of the collision volume. Can be:
Defaults to "box".
Private
_getPrivate
_onPrivate
The parent node.
Private
_updateFire an event, all additional arguments are passed on to the event listener.
Name of event to fire.
Optional
arg1: anyFirst argument that is passed to the event handler.
Optional
arg2: anySecond argument that is passed to the event handler.
Optional
arg3: anyThird argument that is passed to the event handler.
Optional
arg4: anyFourth argument that is passed to the event handler.
Optional
arg5: anyFifth argument that is passed to the event handler.
Optional
arg6: anySixth argument that is passed to the event handler.
Optional
arg7: anySeventh argument that is passed to the event handler.
Optional
arg8: anyEighth argument that is passed to the event handler.
Self for chaining.
obj.fire('test', 'This is the message');
Test if there are any handlers bound to an event name.
The name of the event to test.
True if the object has handlers bound to the specified event name.
obj.on('test', function () { }); // bind an event to 'test'
obj.hasEvent('test'); // returns true
obj.hasEvent('hello'); // returns false
Detach an event handler from an event. If callback is not provided then all callbacks are unbound from the event, if scope is not provided then all events with the callback will be unbound.
Optional
name: stringName of the event to unbind.
Optional
callback: HandleEventCallbackFunction to be unbound.
Optional
scope: objectScope that was used as the this when the event is fired.
Self for chaining.
const handler = function () {
};
obj.on('test', handler);
obj.off(); // Removes all events
obj.off('test'); // Removes all events called 'test'
obj.off('test', handler); // Removes all handler functions, called 'test'
obj.off('test', handler, this); // Removes all handler functions, called 'test' with scope this
Attach an event handler to an event.
Name of the event to bind the callback to.
Function that is called when event is fired. Note the callback is limited to 8 arguments.
Optional
scope: object = ...Object to use as 'this' when the event is fired, defaults to current this.
Can be used for removing event in the future.
obj.on('test', function (a, b) {
console.log(a + b);
});
obj.fire('test', 1, 2); // prints 3 to the console
const evt = obj.on('test', function (a, b) {
console.log(a + b);
});
// some time later
evt.off();
Private
onPrivate
Asset that was removed.
Private
onPrivate
onPrivate
Asset that was removed.
Private
onPrivate
onPrivate
onPrivate
onPrivate
onPrivate
onPrivate
onPrivate
onPrivate
onPrivate
onAttach an event handler to an event. This handler will be removed after being fired once.
Name of the event to bind the callback to.
Function that is called when event is fired. Note the callback is limited to 8 arguments.
Optional
scope: object = ...Object to use as 'this' when the event is fired, defaults to current this.
obj.once('test', function (a, b) {
console.log(a + b);
});
obj.fire('test', 1, 2); // prints 3 to the console
obj.fire('test', 1, 2); // not going to get handled
Static
EVENT_Fired two rigid-bodies stop touching. The handler is passed an Entity that represents the other rigid body involved in the collision.
entity.collision.on('collisionend', (other) => {
console.log(`${entity.name} stopped touching ${other.name}`);
});
Static
EVENT_Fired when two rigid bodies start touching. The handler is passed the ContactResult object which contains details of the contact between the two rigid bodies.
entity.collision.on('collisionstart', (result) => {
console.log(`${entity.name} started touching ${result.other.name}`);
});
Static
EVENT_Fired when a contact occurs between two rigid bodies. The handler is passed a ContactResult object which contains details of the contact between the two rigid bodies.
entity.collision.on('contact', (result) => {
console.log(`Contact between ${entity.name} and ${result.other.name}`);
});
Static
EVENT_Fired when a rigid body enters a trigger volume. The handler is passed an Entity representing the rigid body that entered this collision volume.
entity.collision.on('triggerenter', (other) => {
console.log(`${other.name} entered trigger volume ${entity.name}`);
});
Static
EVENT_Fired when a rigid body exits a trigger volume. The handler is passed an Entity representing the rigid body that exited this collision volume.
entity.collision.on('triggerleave', (other) => {
console.log(`${other.name} exited trigger volume ${entity.name}`);
});
A collision volume. Use this in conjunction with a RigidBodyComponent to make a collision volume that can be simulated using the physics engine.
If the Entity does not have a RigidBodyComponent then this collision volume will act as a trigger volume. When an entity with a dynamic or kinematic body enters or leaves an entity with a trigger volume, both entities will receive trigger events.
The following table shows all the events that can be fired between two Entities: