private void Start() { attachedController = GetComponent <AgentSteering>(); attachedBase = GetComponent <AgentBase>(); attachedController.SetTargetTile(attachedBase.currentTileIndex); currentTask = new AgentTask(Tasks.Null, attachedBase); PrepTaskList(); UpdateAgent(); }
// Drunk gestion private void updateDrunk() { foreach (Agent drunk in m_drunkList) { Vector2 drunkSteer = AgentSteering.leader(drunk._velocity, 20, 0.5f, ref drunk._wanderPoint); Vector2 avoidSteer = AgentSteering.avoid(drunk._position, drunk._velocity, ref drunk._wanderPoint) * _coefAvoidObs; Vector2 force = drunkSteer + avoidSteer; drunk._steeringForce += force; } }
// Leader gestion private void updateLeaders() { foreach (Agent leader in m_leaderList) { Vector2 leadSteer = AgentSteering.leader(leader._velocity, _leaderRadius, _leaderVariation, ref leader._wanderPoint) * _coefLeader; Vector2 avoidSteer = AgentSteering.avoid(leader._position, leader._velocity, ref leader._wanderPoint) * _coefAvoidObs; Vector2 force = leadSteer + avoidSteer; leader._steeringForce += force; } }
// Follower gestion private void updateFollowers() { foreach (Agent follower in m_followerList) { Agent nearestLeader = findNearest(follower, m_leaderList); Vector2 followSteer = AgentSteering.follow(follower._position, nearestLeader._position, nearestLeader._velocity); Vector2 stayOutSteer = AgentSteering.stayOut(follower._position, nearestLeader._position, nearestLeader._velocity) * _coefStayOut; Vector2 force = followSteer + stayOutSteer; follower._steeringForce += force; } }
// Separation gestion private void updateSeparation(Agent [] separationList, float coefSeparation) { foreach (Agent separation in separationList) { Agent[] neighbours = findNeighbours(separation, 20.0f); Vector2[] positionNeighbours = new Vector2[neighbours.Length]; for (int i = 0; i < neighbours.Length; i++) { positionNeighbours.SetValue(neighbours[i]._position, i); } Vector2 steer = AgentSteering.separation(separation._position, positionNeighbours) * coefSeparation; separation._steeringForce += steer; } }