示例#1
0
 public void Enable()
 {
     Debug.Log($"Entered meeting {name}");
     _npc = GetComponent <AgentNPC>();
     _npc.Agent.SetDestination(MeetPosition);
     _animator = GetComponent <Animator>();
 }
示例#2
0
    public override void setSteering(AgentNPC agent)
    {
        // Get direction to the target
        agent.steering.lineal = target.transform.position - agent.transform.position;

        // If there is no direction, do nothing
        if (agent.steering.lineal.sqrMagnitude < target.exteriorRadius * target.exteriorRadius)
        {
            agent.steering.clear();
            return;
        }


        agent.steering.lineal *= (1.0f) / timeToTarget;

        // If that is too fast, then clip the speed
        if (agent.steering.lineal.sqrMagnitude > agent.maxSpeed * agent.maxSpeed)
        {
            agent.steering.lineal  = agent.steering.lineal.normalized;
            agent.steering.lineal *= agent.maxSpeed;
        }


        // Set new orientation
        agent.steering.angular = getNewOrientation(agent.transform.rotation.y, agent.steering.lineal);
    }
示例#3
0
    public void UpdateSlots()
    {
        Agent   leader      = pattern.leader;
        Vector3 anchor      = leader.position;
        float   orientation = leader.orientation;

        foreach (SlotAssignment sa in slotAssignments)
        {
            //Debug.Log ("Analizando Slot Assignment #" + sa.slotIndex);
            AgentNPC character = sa.character.GetComponent <AgentNPC>();

            if (character != leader) // Tiene sentido que el lider no se mueva
            {
                //Debug.Log ("Analizando slot de " + character.name + " en el patron " + pattern);
                Vector3 slotPos = pattern.GetSlotLocation(sa.slotIndex).position;
                Vector3 relPos  = anchor + leader.transform.TransformDirection(slotPos);
                //    Debug.Log(sa.slotIndex + ". SlotPos: " + slotPos + ", relPos: " + relPos);
                Location charDrift = new Location(relPos, orientation);
                //   charDrift.position += driftOffset.position;
                //   Debug.Log("driftOffset.position = " + driftOffset.position);
                // charDrift.orientation += driftOffset.orientation; //Podria ser *
                //	Debug.Log("ASIGNANDO A " + character.name + " LA ORIENTACION " + orientation);
                character.SetFormation(charDrift.position, orientation);    //Queremos que miren a donde mire el lider
            }
        }
    }
示例#4
0
    public override Steering getSteering(AgentNPC agent)
    {
        Steering steering = new Steering();

        foreach (Sensor sensor in sensores)
        {
            float   angulo    = sensor.angulo + Mathf.Atan2(agent.Velocidad.x, agent.Velocidad.z) * Mathf.Rad2Deg;
            Vector3 rayVector = AsVector(angulo);
            rayVector   = rayVector.normalized;
            sensor.rayo = rayVector * sensor.lookAhead;

            collision = collisionDetector.GetCollision(agent.Posicion, sensor.rayo, sensor.rayo.magnitude);

            if (collision != null)
            {
                Vector3 newDir = collision.Posicion + collision.Normal * avoidDistance;
                target.Posicion = new Vector3(newDir.x, newDir.y, newDir.z);

                Destroy(t);
                return(base.getSteering(agent));
            }
        }

        steering.Lineal  = new Vector3(0, 0, 0);
        steering.Angular = 0;

        Destroy(t);
        return(steering);
    }
    public override Steering getSteering(AgentNPC agent)
    {
        Steering steering = new Steering();

        steering.Lineal = target.Posicion - agent.Posicion;

        if (steering.Lineal.magnitude < radio)
        {
            steering.Lineal  = new Vector3(0, 0, 0);
            steering.Angular = 0;
            return(steering);
        }

        steering.Lineal /= timeToTarget;

        if (steering.Lineal.magnitude > agent.MaxSpeed)
        {
            steering.Lineal  = steering.Lineal.normalized;
            steering.Lineal *= agent.MaxSpeed;
        }

        agent.Orientacion = getNewOrientation(agent.Orientacion, steering.Lineal);

        steering.Angular = 0;
        return(steering);
    }
示例#6
0
        // this behaviuor is entered only if the Infirmery has available space
        public void Enable()
        {
            _npc = GetComponent <AgentNPC>();

            Debug.Assert(destination != null, "destination != null");
            _npc.Agent.SetDestination(destination.position);
        }
示例#7
0
    public override Steering getSteering(AgentNPC agent)
    {
        Steering steering = new Steering();

        t = new GameObject();
        t.AddComponent <Kinematic>();

        target = t.GetComponent <Kinematic>();

        wanderOrientation = Random.Range(-1f, 1f) * wanderRate;


        target.Orientacion = wanderOrientation + agent.Orientacion;

        target.Posicion  = agent.Posicion + wanderOffset * asVector(agent.Orientacion);
        target.Posicion += (wanderRadius * asVector(target.Orientacion));

        base.target = target;

        steering        = base.getSteering(agent);
        steering.Lineal = agent.MaxAcceleration * asVector(agent.Orientacion);

        Destroy(t);

        return(steering);
    }
示例#8
0
 public void Enable()
 {
     _animator = GetComponent <Animator>();
     _npc      = GetComponent <AgentNPC>();
     _initialTransformParent = mouse.transform.parent;
     _initialPos             = mouse.transform.localPosition;
     _chairInitialPosition   = chair.transform.position;
 }
    public override Steering getSteering(AgentNPC agent)
    {
        Steering steering = new Steering();

        float shortestTime = Mathf.Infinity;

        Agent   firstTarget        = null;
        float   firstMinSeparation = 0;
        float   firstDistance      = 0;
        Vector3 firstRelativePos   = Vector3.zero;
        Vector3 firstRelativeVel   = Vector3.zero;

        foreach (Agent target in targets)
        {
            Vector3 relativePos     = target.Posicion - agent.Posicion;
            Vector3 relativeVel     = target.Velocidad - agent.Velocidad;
            float   relativeSpeed   = relativeVel.magnitude;
            float   timeToCollision = (new Vector3(relativePos.x + relativeVel.x, 0, relativePos.z + relativeVel.z).magnitude / (relativeSpeed * relativeSpeed));

            float distance      = relativePos.magnitude;
            float minSeparation = distance - relativeSpeed * timeToCollision;

            if (minSeparation > 2 * radius)
            {
                continue;
            }

            if (timeToCollision > 0 && timeToCollision < shortestTime)
            {
                shortestTime       = timeToCollision;
                firstTarget        = target;
                firstMinSeparation = minSeparation;
                firstDistance      = distance;
                firstRelativePos   = relativePos;
                firstRelativeVel   = relativeVel;
            }
        }

        if (firstTarget == null)
        {
            return(steering);
        }

        if (firstMinSeparation <= 0 || firstDistance < 2 * radius)
        {
            firstRelativePos = firstTarget.Posicion - agent.Posicion;
        }
        else
        {
            firstRelativePos += firstRelativeVel * shortestTime;
        }

        firstRelativePos.Normalize();
        steering.Lineal = firstRelativePos * agent.MaxAcceleration;

        return(steering);
    }
示例#10
0
 public PathRequest(AgentNPC unit, Vector3 end, Faction faction, Action <Vector3[], bool> callback)
 {
     this.start    = unit.position;
     this.end      = end;
     this.cost     = unit.Cost;
     this.callback = callback;
     this.faction  = faction;
     this.unit     = unit;
 }
示例#11
0
    public override Steering getSteering(AgentNPC agent)
    {
        Steering steering = new Steering();

        steering.Lineal = agent.MaxSpeed * asVector(agent.Orientacion);


        steering.Angular = Random.Range(-1f, 1f) * agent.MaxRotation;


        return(steering);
    }
示例#12
0
    public override void setSteering(AgentNPC agent)
    {
        // Get direction to the target
        agent.steering.lineal = agent.transform.position - target.transform.position;

        agent.steering.lineal  = agent.steering.lineal.normalized;
        agent.steering.lineal *= agent.maxSpeed;



        // Set new rotation
        agent.steering.angular = getNewOrientation(agent.transform.rotation.y, agent.steering.lineal);
    }
    public override Steering getSteering(AgentNPC agent)
    {
        Steering steering = new Steering();

        steering.Lineal = agent.Posicion - target.Posicion;

        steering.Lineal = steering.Lineal.normalized;

        steering.Lineal *= agent.MaxAcceleration;

        steering.Angular = 0;
        return(steering);
    }
示例#14
0
    public override Steering getSteering(AgentNPC agent)
    {
        Steering steering = null;

        foreach (BlendedSteering group in groups)
        {
            steering = group.getSteering(agent);
            if (steering.Lineal.magnitude > epsilon || Mathf.Abs(steering.Angular) > epsilon)
            {
                return(steering);
            }
        }
        return(steering);
    }
示例#15
0
    public override Steering getSteering(AgentNPC agent)
    {
        if (agent.Velocidad.magnitude == 0)
        {
            Steering steering = new Steering();
            steering.Lineal  = new Vector3(0, 0, 0);
            steering.Angular = 0;
            return(steering);
        }

        target.Orientacion = Mathf.Atan2(agent.Velocidad.x, agent.Velocidad.z) * Mathf.Rad2Deg;

        return(base.getSteering(agent));
    }
示例#16
0
    public override Steering getSteering(AgentNPC agent)
    {
        Steering steering = new Steering();

        steering.Lineal = agent.Posicion - target.Posicion;
        steering.Lineal = steering.Lineal.normalized;

        steering.Lineal *= agent.MaxSpeed;

        agent.Orientacion = getNewOrientation(agent.Orientacion, steering.Lineal);

        steering.Angular = 0;
        return(steering);
    }
示例#17
0
    public override void setSteering(AgentNPC agent)
    {
        // Move forward in the current direction
        // agent.steering.lineal = new Vector3(Mathf.Sin(agent.transform.rotation.eulerAngles.x), 0, Mathf.Cos(agent.transform.rotation.eulerAngles.z));
        //agent.steering.lineal = new Vector3(agent.transform.rotation.eulerAngles.x, 0, agent.transform.rotation.eulerAngles.z);
        agent.steering.lineal = agent.transform.forward * agent.maxSpeed;
        Debug.Log("rotation euler: " + agent.steering.lineal);
        agent.steering.lineal *= agent.maxSpeed;

        // Turn a little
        float change = Random.Range(-1f, 1f);

        agent.steering.angular = change * agent.maxRotation;
    }
示例#18
0
        public IEnumerator OnUpdate()
        {
            while (true)
            {
                if (_startPatroling == false ||
                    _npc.Agent.remainingDistance < _npc.agentConfiguration.stoppingDistance)
                {
                    if (_startPatroling)
                    {
                        _currentDestination = _npc.patrolPositions[_indexPatrol].transform.position;
                    }
                    _startPatroling = true;
                    _npc.Agent.SetDestination(_npc.patrolPositions[_indexPatrol].transform.position);

                    _indexPatrol++;
                    if (_indexPatrol == _npc.patrolPositions.Length)
                    {
                        _indexPatrol = 0;
                    }
                }

                yield return
                    (null); // VERY IMPORTANT TO PAUSE THE EXECUTION HERE, it will make sure that this coroutine can be stopped

                AgentNPC partnerNPC = _npc.MeetSystem.FindNPCToMeet();
                if (partnerNPC != null)
                {
                    // check if the probabilites and the sociable level are satisfied for both
                    var randomValue = Random.Range(1, 10);
                    if (randomValue <= _npc.agentConfiguration.sociableLevel &&
                        randomValue <= partnerNPC.agentConfiguration.sociableLevel)
                    {
                        Debug.Log($"Botul {_npc.name} si {partnerNPC.name}"); // then they actually meet.
                        var talkDuration = Random.Range(8f, 11f);
                        _npc.MeetSystem.Meet(partnerNPC, talkDuration);
                        partnerNPC.MeetSystem.Meet(_npc, talkDuration);
                    }
                    else
                    {
                        Debug.Log(
                            $"<color=red>meeting failed due to probability, expected <= {randomValue} {_npc.name} {partnerNPC.name} </color>");
                        _npc.MeetSystem.IgnoreAgent(partnerNPC, 10); // ignores agent for a number of 10 seconds
                        partnerNPC.MeetSystem.IgnoreAgent(_npc, 10);
                    }
                }

                yield return(null);
            }
        }
示例#19
0
    public override Steering getSteering(AgentNPC agent)
    {
        Steering steering = new Steering();

        foreach (BehaviourAndWeight behaviour in Behaviours)
        {
            Steering steer = behaviour.behaviour.getSteering(agent);
            steering.Lineal  += steer.Lineal * behaviour.weight;
            steering.Angular += steer.Angular * behaviour.weight;
        }

        steering.Lineal = Vector3.ClampMagnitude(steering.Lineal, agent.MaxAcceleration);

        return(steering);
    }
示例#20
0
    public override Steering getSteering(AgentNPC agent)
    {
        Steering steering = new Steering();

        steering.Lineal  = target.Velocidad - agent.Velocidad;
        steering.Lineal /= timeToTarget;

        if (steering.Lineal.magnitude > agent.MaxAcceleration)
        {
            steering.Lineal  = steering.Lineal.normalized;
            steering.Lineal *= agent.MaxAcceleration;
        }

        steering.Angular = 0;
        return(steering);
    }
    public override Steering getSteering(AgentNPC agent)
    {
        Vector3 direction = target.Posicion - agent.Posicion;

        if (direction.magnitude == 0)
        {
            Steering steering = new Steering();
            steering.Lineal  = new Vector3(0, 0, 0);
            steering.Angular = 0;
            return(steering);
        }

        target.Orientacion = Mathf.Atan2(direction.x, direction.z) * Mathf.Rad2Deg;
        Steering st = base.getSteering(agent);

        return(st);
    }
示例#22
0
    public static void RequestPath(AgentNPC agent, Vector3 pathEnd, Faction faction, Action <Vector3[], bool> callback)
    {
        PathRequest newRequest = new PathRequest(agent, pathEnd, faction, callback);

        Debug.Assert(Map.NodeFromPosition(pathEnd).isWalkable());
        if (instance.repetitions.ContainsKey(agent))
        {
            instance.repetitions[agent] += 1;
        }
        else
        {
            instance.repetitions[agent] = 1;
        }

        instance.requestQueue.Enqueue(newRequest);
        instance.ProcessNext();
    }
示例#23
0
    public bool AddCharacter(AgentNPC character)
    {
        int occupiedSlots = slotAssignments.Count;

        if (!pattern.SupportsSlots(occupiedSlots + 1) || character == pattern.leader)
        {
            //		Debug.Log ("NOT Added " + character.name);
            return(false);
        }
        SlotAssignment sa = new SlotAssignment();

        sa.character = character;
        slotAssignments.Add(sa);
        UpdateSlotAssignments();
        //	Debug.Log ("Added " + character.name);
        return(true);
    }
示例#24
0
    public override Steering getSteering(AgentNPC agent)
    {
        Steering steering = new Steering();

        float rotation = target.Orientacion - agent.Orientacion;

        rotation = MapToRange(rotation);

        float rotationSize = Mathf.Abs(rotation);

        if (rotationSize < target.InteriorRadius)
        {
            steering.Lineal  = new Vector3(0, 0, 0);
            steering.Angular = 0;
            return(steering);
        }

        float targetRotation;

        if (rotationSize > target.ExteriorRadius)
        {
            targetRotation = agent.MaxRotation;
        }
        else
        {
            targetRotation = agent.MaxRotation * rotationSize / target.ExteriorRadius;
        }

        targetRotation *= rotation / rotationSize;

        steering.Angular  = targetRotation - agent.Rotacion;
        steering.Angular /= timeToTarget;

        float angularAceleration = Mathf.Abs(steering.Angular);


        if (angularAceleration > agent.MaxAngularAceleration)
        {
            steering.Angular /= angularAceleration;
            steering.Angular *= agent.MaxAngularAceleration;
        }
        steering.Lineal = new Vector3(0, 0, 0);

        return(steering);
    }
示例#25
0
    private void OnTriggerEnter(Collider other)
    {
        _npc = other.gameObject.GetComponent <AgentNPC>();

        if (_npc != null && _occupied == false && _npc.GetComponent <TypingBehaviour>() == null)
        {
            _occupied = true;
            var typingBehaviour = _npc.gameObject.AddComponent <TypingBehaviour>();
            typingBehaviour.targetPosition     = destination;
            typingBehaviour.chairFinalPosition = chairFinalPosition.transform.position;
            typingBehaviour.chair = chair;
            typingBehaviour.mouse = mouse;
            typingBehaviour.correctSittingPosition = chairCorrectPosition.transform.localPosition;
            Debug.Log(typingBehaviour.targetPosition);
            _npc.SetBehaviour(typingBehaviour);
            _collider.enabled = false;
        }
    }
示例#26
0
    private void Start()
    {
        // Initialise every square in the grid as Grass
        for (int x = 0; x < X_DIMENSION; x++)
        {
            grid.Add(new List <Node>());
            for (int z = 0; z < Z_DIMENSION; z++)
            {
                grid[x].Add(new Node(new Vector3(x, 0, z), Node.TerrainType.Grass));

                // Coste por Rol
                AgentNPC agent = gameObject.GetComponent <AgentNPC>();
                if (agent != null)
                {
                    grid[x][z].Rol = agent.TipoR;
                }
            }
        }

        generateGrid();
    }
示例#27
0
    public override Steering getSteering(AgentNPC agent)
    {
        Steering steering = new Steering();

        Vector3 direction = target.Posicion - agent.Posicion;
        float   distance  = direction.magnitude;

        if (distance < target.InteriorRadius)
        {
            steering.Lineal  = new Vector3(0, 0, 0);
            steering.Angular = 0;
            return(steering);
        }

        if (distance > target.ExteriorRadius)
        {
            targetSpeed = agent.MaxSpeed;
        }
        else
        {
            targetSpeed = agent.MaxSpeed * distance / target.ExteriorRadius;
        }

        targetVelocity  = direction;
        targetVelocity  = targetVelocity.normalized;
        targetVelocity *= targetSpeed;

        steering.Lineal  = targetVelocity - agent.Velocidad;
        steering.Lineal /= timeToTarget;

        if (steering.Lineal.magnitude > agent.MaxAcceleration)
        {
            steering.Lineal  = steering.Lineal.normalized;
            steering.Lineal *= agent.MaxAcceleration;
        }

        steering.Angular = 0;
        return(steering);
    }
    public override Steering getSteering(AgentNPC agent)
    {
        radioProx = path.Nodos[nodoActual].Radius;
        target    = path.Nodos[nodoActual].GetComponentInParent <BasicAtrs>();
        if (distancia(agent.Posicion, target.Posicion) <= radioProx)
        {
            nodoActual += pathDir;
        }

        if (nodoActual >= path.Nodos.Length || nodoActual < 0)
        {
            switch (decisionFinal)
            {
            case FinalStep.Reverse:
                pathDir     = -pathDir;
                nodoActual += pathDir;
                break;

            case FinalStep.Init:
                nodoActual = 0;
                break;

            default:
                break;
            }
        }
        Steering steering = new Steering();

        if (target == null)
        {
            steering.Lineal  = Vector3.zero;
            steering.Angular = 0;
            return(steering);
        }
        return(base.getSteering(agent));
    }
示例#29
0
 public abstract void setSteering(AgentNPC agent);
示例#30
0
 private void OnEnable()
 {
     _cachedEditor = null;
     _agentNPC     = target as AgentNPC;
 }