public void Execute(int index)
        {
            var start = GridGeneratorSystem.ClosestNode(AgentGroup.Position[index].Value);
            var goal  = GridGeneratorSystem.ClosestNode(AgentGroup.Target[index].Value);

            Commands.RemoveComponent <Target>(index, AgentGroup.AgentEntity[index]);

            AStarSolver(start, goal, index, AgentGroup.AgentEntity[index]);
        }
Example #2
0
        public void Execute(int i)
        {
            var    index    = Indexes[i];
            float2 agentLoc = Simulator.Instance.getAgentPosition(index);

            SpawnAgentSystem.agents.TryGetValue(index, out var agent);

            int l = waypoints[agent].Length;

            if (l == 0)
            {
                commands.DestroyEntity(i, agent);
                SpawnAgentSystem.agents.Remove(index);
                Simulator.Instance.removeAgent(index);
                return;
            }

            var    next       = GridGeneratorSystem.GridToWorldPos(waypoints[agent][l - 1].Value);
            float2 goalVector = next - agentLoc;

            if (RVOMath.absSq(goalVector) > 1.0f)
            {
                goalVector = math.normalize(goalVector);
            }

            Simulator.Instance.setAgentPrefVelocity(index, goalVector);

            var newPos = new float3(agentLoc.x, 0.15f, agentLoc.y);

            Positions[agent] = new Position {
                Value = newPos
            };

            var dir = next - agentLoc;

            // remove waypoint
            if (dir.x < 0.1f && dir.y < 0.1f)
            {
                waypoints[agent].RemoveAt(l - 1);
            }
        }