The positioning utilities provide methods to find valid positions in the game world, particularly useful for spawning items in accessible locations.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/Bill3621/CustomItems/llms.txt
Use this file to discover all available pages before exploring further.
GetRandomPositionInRoom
Gets a random position within a specified room, attempting to find a location that is accessible to players.Parameters
The room in which to find a random position
Returns
AVector3 representing a valid position in the room, or Vector3.zero if no valid position could be found.
Behavior
This method uses a sophisticated algorithm to find accessible positions:- Attempts up to 100 times to find a valid position
- For each attempt:
- Generates a random point within the room’s bounding box
- Uses
TryGetRoofPositionto find the floor below that point - Converts the position using
RelativePositionfor proper world coordinates - Checks if the position is inside a solid object using
Physics.CheckSphere - Performs raycast validation in four directions (left, right, forward, back)
- For each direction, casts a ray and verifies it hits a surface
- Casts a reverse ray from the hit point to ensure the same collider is hit
- Validates there are no obstructions between the position and room center
- Fallback: If all attempts fail, returns the center of the room at floor level
Raycast Validation
The method performs extensive raycast checks to avoid spawning items:- Inside walls or other objects
- Behind inaccessible barriers
- In positions where rays cannot return (indicating holes or gaps)
Example
Notes
- May rarely return a position behind a wall that is unreachable by players
- Returns
Vector3.zeroif the room is destroyed - Uses
FpcStateProcessor.Maskfor physics checks to detect solid surfaces
GetRandomPosition
Gets a random position in any room in the facility.Returns
AVector3 representing a random position in a randomly selected room, or Vector3.zero if no valid position could be found.
Behavior
- Filters all rooms to exclude destroyed rooms
- Randomly selects one room from the list
- Uses
TryGetRoofPositionwith the room’s center position to find floor level - Converts to world coordinates using
RelativePosition
Example
Notes
- This is a simpler alternative to
GetRandomPositionInRoomwhen the specific room doesn’t matter - Does not perform the extensive validation that
GetRandomPositionInRoomdoes - May occasionally return less accessible positions
GetRandomPointInBounds
Generates a random point within a specified bounding box.Parameters
The bounding box within which to generate a random point
Returns
AVector3 representing a random point inside the bounds.
Behavior
- Generates a random point inside a unit sphere using
UnityEngine.Random.insideUnitSphere - Scales the point by the bounds’ extents on each axis
- Offsets the result by the bounds’ center
Example
Notes
- This is a low-level utility used internally by
GetRandomPositionInRoom - Does not validate if the position is accessible or inside solid objects
- Always returns a point within the mathematical bounds, but may be inside walls
TryGetRoofPosition
Finds the floor position below a given point by raycasting upward to the ceiling.Parameters
The starting point from which to cast a ray upward
When this method returns, contains the calculated floor position if successful, or Vector3.zero if no ceiling was found
Returns
true if a ceiling was found above the point; otherwise, false.
Behavior
- Casts a ray upward from the given point
- If the ray hits a surface within 30 units:
- Calculates the floor position as 0.3 units below the hit point
- Returns the adjusted position
- If no surface is hit, returns
Vector3.zero
Example
Notes
- This is an internal method primarily used by other positioning utilities
- The 0.3 unit offset prevents items from spawning exactly on the surface
- Uses a maximum raycast distance of 30 units
- Uses
FpcStateProcessor.Maskto detect solid surfaces