Example #1
0
            public void Execute(int index, [ReadOnly] ref LocalToWorld localToWorld)
            {
                var floorVal = math.floor(localToWorld.Position / cellRadius);
                var hash     = (int)Unity.Mathematics.math.hash(floorVal);

                hashMap.Add(hash, index);
            }
Example #2
0
            public void Execute(int index, [ReadOnly] ref LocalToWorld localToWorld)
            {
                var ptr = cellPtr0.GetPointer(index);

                ptr->Separation = localToWorld.Position;
                ptr->Alignment  = localToWorld.Forward;
                ptr->Count      = 1;
            }
Example #3
0
            public void Execute(int index, ref LocalToWorld localToWorld)
            {
                var forward         = localToWorld.Forward;
                var currentPosition = localToWorld.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
                localToWorld.Position = localToWorld.Position + (nextHeading * (settings.MoveSpeed * DeltaTime));
                localToWorld.Forward  = nextHeading;
            }
Example #4
0
 public void Execute(Entity *entity, ref LocalToWorld localToWorld)
 {
 }