public void Execute(ref Transform3D transform3D, ref BoidState boidState) { if (boidState.IsDied) { return; } var len = obstaclePositions.m_Length; if (len == 0) { return; } var ptr = obstaclePositions.GetPointer(0); for (int i = 0; i < len; ++i, ++ptr) { var dist = (transform3D.Position - ptr->Position).sqrMagnitude; var sqrScale = ptr->Scale * ptr->Scale; if (dist < MinSqrMagnitude * sqrScale) { boidState.IsDied = true; boidState.IsScored = false; boidState.SinkTimer = SinkTime; boidState.Killer = obstacleIdxs[i]; } } }
public void Execute(ref Transform3D transform3D, ref BoidState boidState) { if (!boidState.IsDied) { return; } boidState.SinkTimer -= DeltaTime; transform3D.Position += SinkOffset; }
public void Execute(int index, ref Transform3D transform3D, ref BoidState boidState) { if (boidState.IsDied) { return; } var forward = transform3D.Forward; var currentPosition = transform3D.Position; var cellIndex = CellDatas.GetPointer(index)->Index; var ptr = CellDatas.GetPointer(cellIndex); var neighborCount = ptr->Count; var alignment = ptr->Alignment; var separation = ptr->Separation; var nearestObstacleDistance = ptr->ObstacleDistance; var nearestObstaclePositionIndex = ptr->ObstaclePositionIndex; var nearestTargetPositionIndex = ptr->TargetPositionIndex; var nearestObstaclePosition = *(ObstaclePositions.GetPointer(nearestObstaclePositionIndex)); var nearestTargetPosition = *(TargetPositions.GetPointer(nearestTargetPositionIndex)); // steering calculations based on the boids algorithm var obstacleSteering = currentPosition - nearestObstaclePosition; var avoidObstacleHeading = (nearestObstaclePosition + math.normalizesafe(obstacleSteering) * Settings.ObstacleAversionDistance) - currentPosition; var targetHeading = Settings.TargetWeight * math.normalizesafe(nearestTargetPosition - currentPosition); var nearestObstacleDistanceFromRadius = nearestObstacleDistance - Settings.ObstacleAversionDistance; var alignmentResult = Settings.AlignmentWeight * math.normalizesafe((alignment / neighborCount) - forward); var separationResult = Settings.SeparationWeight * math.normalizesafe((currentPosition * neighborCount) - separation); var normalHeading = math.normalizesafe(alignmentResult + separationResult + targetHeading); var targetForward = math.select(normalHeading, avoidObstacleHeading, nearestObstacleDistanceFromRadius < 0); var nextHeading = math.normalizesafe(forward + DeltaTime * (targetForward - forward)); // updates based on the new heading transform3D.Position = transform3D.Position + (nextHeading * (Settings.MoveSpeed * DeltaTime)); transform3D.Forward = nextHeading; }
private int _GetOffsetOfBoidState_Killer() { var tempObj = new BoidState(); BoidState *ptr = &tempObj; var filedPtr = &(ptr->Killer); return((int)((long)filedPtr - (long)ptr)); }
private int _GetOffsetOfBoidState_IsScored() { var tempObj = new BoidState(); BoidState *ptr = &tempObj; var filedPtr = &(ptr->IsScored); return((int)((long)filedPtr - (long)ptr)); }