Collider
Colliders are attached to GameEntities and when two colliders intersect, it triggers the onCollision() method in the GameEntity
Properties
colliderType(string) — The type of this collider - should be defined in sub classes (eg. "circle", "rectangle")name(string) — Name this collider will be identified byenabled(boolean) — Does this collider trigger onCollision() ?offset(BGE.Math.Vector) — Offset from the GameEntity it is attached tomemberFlags(integer) — Bitflag for collision detection: this collider is in this group - https://developer.roku.com/en-ca/docs/references/brightscript/interfaces/ifsprite.md#setmemberflagsflags-as-integer-as-voidcollidableFlags(integer) — Bitflag for collision detection: this collider will only collider with colliders in this group - https://developer.roku.com/en-ca/docs/references/brightscript/interfaces/ifsprite.md#setcollidableflagsflags-as-integer-as-voidcompositorObject(roSprite) — Used internal to Game - should not be modified manuallycontacts(roAssociativeArray) — Used internal to Game - should not be modified manually. Colliders overlapped last frame,tagsList(dynamic) — Colliders can be tagged with any number of tags so they can be easily identified (e.g. "enemy", "wall", etc.)
Constructor
new Collider(
colliderName: string,
args?: roAssociativeArray,
): ColliderCreates a new Collider
Parameters
colliderName(string) — the name this collider will be identified byargs(roAssociativeArray, optional, default: "{}") — additional properties to be added to this collider
Instance Methods
setupCompositor(
game,
gameEngine: Game,
entityName: string,
entityId: string,
entityPosition: BGE.Math.Vector,
): void
Sets up this collider to be associated with a given game and entity
Parameters
game— the game this collider is used bygameEngine(Game)entityName(string) — name of the entity that owns this colliderentityId(string) — id of the entity that owns this colliderentityPosition(BGE.Math.Vector) — entity's position
Returns
void
refreshColliderRegion(): void
Refreshes the collider. Called every frame by the GameEngine. Should be overridden by sub classes if they have specialized collision set ups (e.g. circle, rectangle).
Returns
void
adjustCompositorObject(entityPosition: BGE.Math.Vector): void
Moves the compositor to the new x,y position - called from Game when the entity it is attached to moves
Parameters
entityPosition(BGE.Math.Vector)
Returns
void
checkCollisions(entityPosition: BGE.Math.Vector): Array.<object>
Runs this collider's broad-phase overlap check against every other collider currently registered in the compositor, moving this collider to entityPosition first. Called once per frame, per enabled collider, from Game.processEntityOnCollision(). Overridden by SphereCollider3d/BoxCollider3d to combine two internal 2D colliders' own checkCollisions() results into one true-3D-aware candidate list.
Parameters
entityPosition(BGE.Math.Vector) — the owning entity's current position
Returns
Array.<object>— one {entityId, objectName, colliderName} record per broad-phase candidate (identifying the OTHER entity/collider each candidate collided with)
confirmCollision(
myEntity: GameEntity,
otherCollider: Collider,
otherEntity: GameEntity,
): boolean
Called once per checkCollisions() candidate, before onCollision() fires, as a final gate. The base implementation always confirms (the broad-phase result already is the final answer for a plain 2D collider) - overridden by SphereCollider3d/BoxCollider3d to run a precise 3D math check, since their own broad-phase can produce false positives (see SphereCollider3d's own doc comment).
Parameters
myEntity(GameEntity) — the entity this collider is attached tootherCollider(Collider) — the other entity's collider that broad-phase matchedotherEntity(GameEntity)
Returns
boolean— true if this candidate is a genuine collision
raycastCheck(
entityPosition: BGE.Math.Vector,
rayOrigin: BGE.Math.Vector,
rayDirection: BGE.Math.Vector,
maxDistance: float,
): BGE.RaycastHit
Tests this collider's shape against a ray. The base implementation always misses - overridden by CircleCollider/RectangleCollider/SphereCollider3d/BoxCollider3d, each computing its own world-space geometry from entityPosition + m.offset and delegating to the matching BGE.intersectRay*() function (see colliders/Raycast.bs). Called by Game.raycast()/Game.raycastAll() - the returned hit's entity/collider fields are left invalid here and filled in by the caller, which is the only place that has both the owning GameEntity and this Collider in hand at once. If rayOrigin is already inside this collider's shape, the override returns a hit at distance: 0/point: rayOrigin rather than invalid - every BGE.intersectRay*() function follows this same "origin inside returns t=0" convention.
Parameters
entityPosition(BGE.Math.Vector) — the owning entity's current positionrayOrigin(BGE.Math.Vector)rayDirection(BGE.Math.Vector) — must be a unit vectormaxDistance(float)
Returns
BGE.RaycastHit— the intersection, orinvalidif the ray misses
disableCollisionChecking(): void
Zeroes this collider's member/collidable flags so it stops participating in collision checks, without removing it from the compositor. Called every frame by Game.processEntityOnCollision() for a disabled collider. Overridden by SphereCollider3d/BoxCollider3d to disable both of their internal 2D colliders.
Returns
void
removeFromCompositor(): void
Removes this collider's compositor object(s) from the compositor. Called by GameEntity.removeCollider() during teardown (entity destroy, non-persistent scene change). Overridden by SphereCollider3d/BoxCollider3d to remove both of their internal colliders' sprites, since this class's own m.compositorObject is never set.
Returns
void
debugDraw(
renderObj: BGE.Renderer,
position: BGE.Math.Vector,
color?: integer,
addName?: boolean,
font?: roFont,
): void
Helper function to draw an outline around the collider
Parameters
renderObj(BGE.Renderer)position(BGE.Math.Vector)color(integer, optional, default: "&hFF0000FF")addName(boolean, optional, default: false)font(roFont, optional, default: "invalid")
Returns
void