SphereCollider3d

Extends: Collider

A collider with the shape of a sphere centered at (offset.x, offset.y, offset.z) with given radius, that detects a true 3D overlap - not just an XY-space projection.

Internally, this owns two ordinary CircleColliders for broad-phase: one tracking the entity's real (x, y) - the same XY plane every other 2D Collider uses - and one tracking a synthetic (y, z) "YZ plane", flagged with COLLIDER_3D_YZ_PLANE_FLAG so it can only ever match another YZ-plane collider (both register against the same roCompositor as ordinary 2D colliders, so without this flag a YZ-plane collider could spuriously match an unrelated 2D collider at the same numeric (x, y) position). A pair only becomes a broad-phase candidate when it overlaps on BOTH planes - and even then, confirmCollision() runs a true sphere-sphere distance check before accepting it, because two spheres can pass both plane checks while never actually touching in 3D (a diagonal near-miss). See specs/2026-09-18-3d-collision-detection-design.md.

Properties

  • radius (float) — Radius of the sphere
  • lastCollisionResult (Sphere3dCollisionResult) — The most recent confirmCollision() result, readable from onCollision() to compute a

Constructor

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

Create a new SphereCollider3d

Parameters

  • colliderName (string) — name of this collider
  • args (roAssociativeArray, optional, default: "{}") — additional properties (e.g {radius: 10})

Instance Methods

setupCompositor( gameEngine: Game, entityName: string, entityId: string, entityPosition: BGE.Math.Vector, ): void

Parameters

  • gameEngine (Game)
  • entityName (string)
  • entityId (string)
  • entityPosition (BGE.Math.Vector)

Returns

  • void

checkCollisions(entityPosition: BGE.Math.Vector): Array.<object>

Parameters

  • entityPosition (BGE.Math.Vector)

Returns

  • Array.<object>

confirmCollision( myEntity: object, otherCollider: Collider, otherEntity: object, ): boolean

Parameters

  • myEntity (object)
  • otherCollider (Collider)
  • otherEntity (object)

Returns

  • boolean

raycastCheck( entityPosition: BGE.Math.Vector, rayOrigin: BGE.Math.Vector, rayDirection: BGE.Math.Vector, maxDistance: float, ): BGE.RaycastHit

Parameters

  • entityPosition (BGE.Math.Vector)
  • rayOrigin (BGE.Math.Vector)
  • rayDirection (BGE.Math.Vector)
  • maxDistance (float)

Returns

disableCollisionChecking(): void

Returns

  • void

adjustCompositorObject(entityPosition: BGE.Math.Vector): void

Parameters

  • entityPosition (BGE.Math.Vector)

Returns

  • void

removeFromCompositor(): void

Returns

  • void

debugDraw( renderObj: Renderer, position: BGE.Math.Vector, color?: integer, addName?: boolean, font?: roFont, ): void

Parameters

  • renderObj (Renderer)
  • position (BGE.Math.Vector)
  • color (integer, optional, default: "&hFF0000FF")
  • addName (boolean, optional, default: false)
  • font (roFont, optional, default: "invalid")

Returns

  • void