Collider

Colliders are attached to GameEntities and when two colliders intersect, it triggers the onCollision() method in the GameEntity

Properties


Constructor

new Collider( colliderName: string, args?: roAssociativeArray, ): Collider

Creates a new Collider

Parameters

  • colliderName (string) — the name this collider will be identified by
  • args (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 by
  • gameEngine (Game)
  • entityName (string) — name of the entity that owns this collider
  • entityId (string) — id of the entity that owns this collider
  • entityPosition (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 to
  • otherCollider (Collider) — the other entity's collider that broad-phase matched
  • otherEntity (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 position
  • rayOrigin (BGE.Math.Vector)
  • rayDirection (BGE.Math.Vector) — must be a unit vector
  • maxDistance (float)

Returns

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