Options
All
  • Public
  • Public/Protected
  • All
Menu

CollisionGroups indicate like members that do not collide with each other. Use CollisionGroupManager to create CollisionGroups

For example:

Players have collision group "player"

Player Collision Group

Enemies have collision group "enemy"

Enemy Collision Group

Blocks have collision group "ground"

Ground collision group

Players don't collide with each other, but enemies and blocks. Likewise, enemies don't collide with each other but collide with players and blocks.

This is done with bitmasking, see the following pseudo-code

PlayerGroup = 0b001 PlayerGroupMask = 0b110

EnemyGroup = 0b010 EnemyGroupMask = 0b101

BlockGroup = 0b100 BlockGroupMask = 0b011

Should Players collide? No because the bitwise mask evaluates to 0 (player1.group & player2.mask) === 0 (0b001 & 0b110) === 0

Should Players and Enemies collide? Yes because the bitwise mask is non-zero (player1.group & enemy1.mask) === 1 (0b001 & 0b101) === 1

Should Players and Blocks collide? Yes because the bitwise mask is non-zero (player1.group & blocks1.mask) === 1 (0b001 & 0b011) === 1

Hierarchy

  • CollisionGroup

Index

Constructors

Properties

Accessors

Methods

Constructors

constructor

  • new CollisionGroup(name: string, category: number, mask: number): CollisionGroup

Properties

Static All

All: CollisionGroup = new CollisionGroup('Collide with all groups', -1, -1)

The All CollisionGroup is a special group that collides with all other groups including itself, it is the default collision group on colliders.

Accessors

category

  • get category(): number

mask

  • get mask(): number

name

  • get name(): string

Methods

canCollide