Skip to content

Game.Simulation.CreatureCollisionIterator

Assembly: Assembly-CSharp
Namespace: Game.Simulation

Type: struct

Base: INativeQuadTreeIterator, IUnsafeQuadTreeIterator

Summary:
CreatureCollisionIterator is a value-type iterator used by creature (human/animal) movement logic to detect and respond to collisions with static and moving objects, lane objects and other creatures. It queries quad-trees and lane buffers, computes target lines and bounds, tests distances and vertical overlap, determines blockers and queueing behavior, and adjusts target positions and allowed speeds accordingly. This struct centralizes collision resolution (including push-away logic, queue detection, and braking) used during creature path-following and lane iteration.


Fields

  • public ComponentLookup<Owner> m_OwnerData
    Lookup for Owner component: used to access owner/parent entity information for lanes/areas.

  • public ComponentLookup<Transform> m_TransformData
    Lookup for Transform component (position/rotation): used to obtain world positions and orientations of other entities.

  • public ComponentLookup<Moving> m_MovingData
    Lookup for Moving component (velocity): used to detect and reason about moving objects/creatures.

  • public ComponentLookup<Creature> m_CreatureData
    Lookup for Creature component: used to read creature-specific data such as queue areas and queue entity.

  • public ComponentLookup<GroupMember> m_GroupMemberData
    Lookup for GroupMember component: used to resolve leader/member relationships when checking queues.

  • public ComponentLookup<Waypoint> m_WaypointData
    Lookup for Waypoint component: used when walking path includes waypoints.

  • public ComponentLookup<TaxiStand> m_TaxiStandData
    Lookup for TaxiStand component: used when path elements target taxi stands.

  • public ComponentLookup<Curve> m_CurveData
    Lookup for Curve component: used for lane curve geometry (bezier) and length queries.

  • public ComponentLookup<AreaLane> m_AreaLaneData
    Lookup for AreaLane component: used when lanes are area lanes (not standard curve lanes).

  • public ComponentLookup<PrefabRef> m_PrefabRefData
    Lookup for PrefabRef component: used to get prefab index/metadata for entities (to fetch geometry/preset data).

  • public ComponentLookup<ObjectGeometryData> m_PrefabObjectGeometryData
    Lookup for ObjectGeometryData per prefab: used to get bounds, flags (WalkThrough, Standing, LowCollisionPriority, etc.), leg sizes, etc.

  • public ComponentLookup<NetLaneData> m_PrefabLaneData
    Lookup for lane prefab data (NetLaneData): used to compute lane width/offset when projecting creature on lanes.

  • public BufferLookup<LaneObject> m_LaneObjects
    Buffer lookup for lane objects on a lane entity: used to check lane-attached objects (bench, sign, etc.) near a curve position.

  • public BufferLookup<Game.Areas.Node> m_AreaNodes
    Buffer lookup for area nodes: used to read polygon nodes of area lanes when computing intersections.

  • public NativeQuadTree<Entity, QuadTreeBoundsXZ> m_StaticObjectSearchTree
    Quad-tree of static objects (non-moving) used for spatial queries to find static obstacles.

  • public NativeQuadTree<Entity, QuadTreeBoundsXZ> m_MovingObjectSearchTree
    Quad-tree of moving objects (other creatures/vehicles) used for spatial queries to find dynamic obstacles.

  • public Entity m_Entity
    The creature entity performing the iteration (self).

  • public Entity m_Leader
    Leader entity for this creature (if part of a group); used when resolving queues / group behavior.

  • public Entity m_CurrentLane
    Entity ID of the current lane the creature is on.

  • public Entity m_CurrentVehicle
    If the creature is in a vehicle, this is the vehicle entity; used to modify queuing behavior.

  • public float m_CurvePosition
    Current curve position (lane parameter) along the lane's bezier for the creature.

  • public float m_TimeStep
    Simulation timestep used when predicting motion and braking.

  • public ObjectGeometryData m_PrefabObjectGeometry
    Geometry data for this creature's prefab: bounds, flags, leg geometry used for collision/queue computations.

  • public Bounds1 m_SpeedRange
    Allowed speed range for the creature (min/max) used to clamp computed speeds.

  • public float3 m_CurrentPosition
    Current world-space position of the creature.

  • public float3 m_CurrentDirection
    Current facing/direction vector of the creature (used for dot products and forward projection).

  • public float3 m_CurrentVelocity
    Current velocity vector of the creature.

  • public float m_TargetDistance
    Maximum look-ahead distance when computing a target line / target position for collision checks.

  • public PathOwner m_PathOwner
    Path owner structure for the creature's path: used to inspect current path state and element index.

  • public DynamicBuffer<PathElement> m_PathElements
    Dynamic buffer containing the creature's path elements (targets along path).

  • public float m_MinSpeed
    Minimum allowed speed (lower clamp) used when adjusting speeds because of obstacles.

  • public float3 m_TargetPosition
    The current target position the creature is trying to reach (on the lane/queue/next element).

  • public float m_MaxSpeed
    Current computed maximum allowed speed after collision/queue resolution (lowered by blockers).

  • public float m_LanePosition
    Lane-relative parameter used for lane offset computation when projecting positions.

  • public Entity m_Blocker
    Entity that currently blocks this creature (closest/most restrictive obstacle discovered).

  • public BlockerType m_BlockerType
    Type of blocker (e.g., Crossing, Continuing, Limit) describing how the obstacle should be handled.

  • public Entity m_QueueEntity
    Entity representing the queue the creature might join (if any).

  • public Sphere3 m_QueueArea
    Area describing the queue region the creature might join or be influenced by.

  • public DynamicBuffer<Queue> m_Queues
    Buffer of queue entries being tracked/updated during iteration (temporary per-iteration state).

  • private Line3.Segment m_TargetLine
    Internally computed 3D segment representing the target corridor/line used for collision checks.

  • private float m_PushFactor
    Internal factor used to compute push-away magnitude; halves each time to reduce iterative push.

  • private Bounds3 m_Bounds
    Computed 3D bounds (expanded target area) used to quickly reject quad-tree nodes.

  • private float m_Size
    Radius/half-width used for the creature's collision footprint derived from prefab geometry.

Properties

  • This struct exposes no public properties. (All state is public fields; there is no explicit property defined in the source.)

Constructors

  • public CreatureCollisionIterator()
    As a struct there is no explicit constructor in the source — use the default value-type constructor and then populate the public fields before calling iteration methods. Populate lookups, quad-trees, geometry and path-related fields before use.

Methods

  • public bool IterateFirstLane(Entity currentLane, float2 currentOffset, bool isBackward)
    Convenience overload that calls IterateFirstLane with current lane as target lane. Initializes size/push factor and runs iteration over moving and static quad-trees when target is an area lane, or checks lane objects and static quad-tree when target is a curve lane.

  • public bool IterateFirstLane(Entity currentLane, Entity targetLane, float2 currentOffset, float2 targetOffset, bool isBackward)
    Primary entry to begin lane iteration/collision checking for a lane transition or initial lane. Sets up collision footprint, computes the target line (area lane or curve) and queries lane objects, moving and static quadtrees as appropriate. Returns whether a lane-object intersection was found (useful for proximity checks).

  • public bool IterateNextLane(Entity nextLane, float2 nextOffset)
    Called when iterating subsequent path lanes: checks lane objects in the provided lane for close objects, or if area lane, triggers moving tree iteration. Returns whether lane-object proximity intersection occurred.

  • public bool Intersect(QuadTreeBoundsXZ bounds)
    Quad-tree intersection test used by the quad-tree iterator: checks mask flags and whether the iterator's computed bounds intersect the quad-tree node bounds; used to cull nodes early.

  • public void Iterate(QuadTreeBoundsXZ bounds, Entity item)
    Quad-tree callback invoked for each matching entity: verifies mask and bounds intersection, and if valid calls CheckCollision(item).

  • private void CalculateTargetLine(Entity targetLane, float3 targetPosition, bool isBackward)
    Compute a target line segment for area lanes using area polygon nodes and the requested target position. Generates a corridor segment that represents permissible target positions within m_TargetDistance and sets m_Bounds to an expanded envelope for spatial queries.

  • private void CalculateTargetLine(Entity targetLane, float targetOffset)
    Compute a target line segment for curve lanes using the lane bezier and lane width (prefab lane data). Clamps the computed line with respect to m_TargetDistance and sets m_Bounds to the corridor envelope.

  • private void CheckCollision(Entity other)
    Core collision evaluation routine called for each potentially colliding entity. Handles:

  • skipping entities that are walk-through,
  • moving-object vs moving-object predictions using velocities and segments, distance check and vertical overlap,
  • push-away adjustments to m_TargetPosition and m_LanePosition,
  • queue checks and speed limit computation for movers (continuing/crossing logic),
  • static object collision logic and speed limit computation (limit blocker type). This method sets m_MaxSpeed, m_Blocker, m_BlockerType and queue info as appropriate when a more restrictive obstacle is found.

  • private bool CheckQueue(Entity other, out Entity queueEntity, out Sphere3 queueArea)
    Checks if another creature has a queue area and whether this iterator's creature should consider joining/being affected by that queue. Uses leader/group-member resolution and compares against current path and lane state. Returns true and fills out queueEntity/queueArea if relevant.

  • private bool ShouldQueue(Entity entity, Sphere3 area, out Sphere3 queueArea)
    Determines whether the given queue entity/area should cause this creature to queue. Maintains and updates m_Queues buffer with observed queues (adds entries if needed). Uses path elements and current lane to map queue target positions, computes queue areas and tests intersection.

  • private float3 GetTargetPosition(int elementIndex, Entity targetElement, float curvePos)
    Resolve a target world position for a given path element index and target entity. If the target is a curve lane, returns a lane position accounting for lane offset; otherwise uses the transform position if present, or falls back to the current target position.

  • public void IterateBlocker(HumanData prefabHumanData, Entity other)
    Specialized blocker iteration for human-type creatures. If 'other' has a queue and is moving, compute braking distance and resulting allowed speed using CreatureUtils.GetMaxBrakingSpeed and clamp by m_SpeedRange. If this braking speed is more restrictive than current m_MaxSpeed, update blocker and queue info and set BlockerType. Used to process single explicit blocking candidate.

  • public void IterateBlocker(AnimalData prefabAnimalData, Entity other)
    Specialized blocker iteration for animal-type creatures. Same logic as human overload but calls CreatureUtils.GetMaxBrakingSpeed with AnimalData variant to compute braking behavior and potential queue involvement.

Usage Example

// Example: prepare and run collision iteration for a creature before moving.
// Populate a CreatureCollisionIterator instance with required lookups, quadtrees,
// current state and prefab geometry, then call IterateFirstLane/IterateNextLane as
// the path/lane iteration proceeds.

CreatureCollisionIterator iter = default;
iter.m_OwnerData = ownerLookup;
iter.m_TransformData = transformLookup;
iter.m_MovingData = movingLookup;
iter.m_CreatureData = creatureLookup;
iter.m_GroupMemberData = groupMemberLookup;
iter.m_CurveData = curveLookup;
iter.m_AreaLaneData = areaLaneLookup;
iter.m_PrefabRefData = prefabRefLookup;
iter.m_PrefabObjectGeometryData = prefabObjectGeometryLookup;
iter.m_PrefabLaneData = prefabLaneLookup;
iter.m_LaneObjects = laneObjectsBufferLookup;
iter.m_AreaNodes = areaNodesBufferLookup;
iter.m_StaticObjectSearchTree = staticTree;
iter.m_MovingObjectSearchTree = movingTree;

iter.m_Entity = creatureEntity;
iter.m_CurrentPosition = currentPos;
iter.m_CurrentDirection = currentDir;
iter.m_CurrentVelocity = currentVel;
iter.m_TargetPosition = desiredTarget;
iter.m_TargetDistance = 8f;
iter.m_TimeStep = deltaTime;
iter.m_PrefabObjectGeometry = myPrefabGeometry;
iter.m_SpeedRange = new Bounds1(minSpeed, maxSpeed);
iter.m_MaxSpeed = iter.m_SpeedRange.max;
iter.m_Queues = queuesBuffer;
iter.m_PathOwner = pathOwner;
iter.m_PathElements = pathElementsBuffer;
iter.m_CurrentLane = currentLaneEntity;
iter.m_CurvePosition = currentCurvePos;

// Start checking collisions against the current lane and lane objects
bool closeLaneObject = iter.IterateFirstLane(iter.m_CurrentLane, new float2(iter.m_CurvePosition, 0f), isBackward: false);

// After iteration, check iter.m_MaxSpeed, iter.m_Blocker, iter.m_QueueEntity for decision making.