Skip to content

@temporary-escape/mod-sdk / findRandomFreePosition

Function: findRandomFreePosition() ​

ts
function findRandomFreePosition(
   scene: Scene, 
   rng: Random, 
   radius: number, 
   center: Vector3f, 
   distance: number, 
   height: number
): Vector3f | null;

Defined in: placement.ts:33

Placement inside a bounded region: picks a deterministic random position that does not overlap any existing collision body, within a disc around center. Use this for content placed as part of world generation (stations, structures) where the region is known.

radius is the placed entity's own clearance radius (typically Entity.getBoundsRadius() plus any padding). The returned position is safe to assign before the entity adds its collision shape and rigid body, which is required for static entities (a static body must not be moved after it is added to the world).

Returns null when no free candidate was found after a fixed number of attempts; callers should fall back to a known position.

Parameters ​

ParameterType
sceneScene
rngRandom
radiusnumber
centerVector3f
distancenumber
heightnumber

Returns ​

Vector3f | null