void Start()
    {
        slotAs   = formation.getSlotByNumber(slot);
        objetivo = new GameObject(); //Creo el objetivo
        objetivo.AddComponent <Kinematic>();

        kinetic = objetivo.GetComponent <Kinematic>();
    }
Exemplo n.º 2
0
    public void updateSlotAssignments()
    {
        for (int i = 0; i < GetPersonajes().Count; i++)
        {
            SlotAssignment slot = new SlotAssignment(GetPersonajes()[i], i);

            SlotAssignments.Add(slot);
        }
    }
    public override SteeringOutPut GetSteering(Kinematic character)
    {
        slotAs = formation.getSlotByNumber(slot);

        kinetic.posicion    = slotAs.Location.Posicion;
        kinetic.orientacion = slotAs.Location.Orientacion;
        arrive.target       = kinetic;
        align.target        = kinetic;
        return(base.GetSteering(character));
    }
Exemplo n.º 4
0
        public void AddsCorrectly()
        {
            var instruction  = new SlotAssignment("test", "AMAZON.Number");
            var instructions = new SceneInstructions();

            instructions.Add(instruction);
            var result = Assert.Single(instructions.Instructions);

            Assert.Equal(instruction, result);
        }
Exemplo n.º 5
0
    public bool AddCharacter(GameObject character)
    {
        int occupiedSlots = slotAssignments.Count;

        if (!pattern.SupportsSlots(occupiedSlots + 1))
        {
            return(false);
        }
        SlotAssignment sa = new SlotAssignment();

        sa.character = character;
        slotAssignments.Add(sa);
        UpdateSlotAssignments();
        return(true);
    }
Exemplo n.º 6
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);
    }
Exemplo n.º 7
0
 // Use this for initialization
 void Start()
 {
     pattern         = new FormationPattern(characterRadius, numberOfSlots);
     slotAssignments = new List <SlotAssignment> ();
     completedTunnel = new List <bool> ();
     for (int i = 0; i < numberOfSlots; i++)
     {
         SlotAssignment slot = new SlotAssignment();
         slot.slotNumber = i;
         slot.character  = Instantiate(unitPrefab);
         slotAssignments.Add(slot);
         completedTunnel.Add(false);
     }
     anchorPoint  = pattern.getDriftOffset(slotAssignments);
     currentIndex = 0;
     rbody        = GetComponent <Rigidbody2D> ();
     completed    = false;
     walls        = GameObject.FindGameObjectsWithTag("Wall");
 }
Exemplo n.º 8
0
        /// <summary>
        /// Adds a new character to the first available slot. Returns false if no more slots are available.
        /// </summary>
        public bool AddCharacter(Entity character)
        {
            // find out how many slots we have occupied
            int occupiedSlots = slotAssignments.Count;

            // check if the pattern supports more slots
            if (!pattern.SupportsSlots(occupiedSlots + 1))
                return false;

            // add a new slot assignment
            var slotAssignment = new SlotAssignment();
            slotAssignment.character = character;

            slotAssignments.Remove(character);
            slotAssignments.Add(character, slotAssignment);

            // update the slot assignents and return success
            UpdateSlotAssignments();

            pattern.Add(slotAssignment);

            return true;
        }
Exemplo n.º 9
0
    // Update is called once per frame
    void Update()
    {
        CheckIfThereIsDestroyedUnit();
        Vector3 averageVelocity = getAverageVelocity();
        Vector3 anchorPosition  = offsetConstant * averageVelocity + getAverageUnitPosition();

        pattern.characterRadius = characterRadius;
        if (goingThroughTunnel)
        {
            setFormationStop();
            SlotAssignment currentSlot     = slotAssignments [unitInTunnelIndex];
            Vector3        currentPosition = currentSlot.character.transform.position;
            Rigidbody2D    rb = currentSlot.character.GetComponent <Rigidbody2D> ();

            if (!inTunnel)
            {
                if (Vector3.Distance(currentPosition, path [2].transform.position) < 0.2f)
                {
                    inTunnel    = true;
                    rb.velocity = Vector2.zero;
                }
                else
                {
                    Vector2 arriveAcceleration = DynamicSeek(currentPosition, path [2].transform.position, formationUnitMaxAcceleration);
                    arriveAcceleration += DynamicArrive(currentPosition, path [2].transform.position, rb.velocity, formationUnitMaxVelocity, formationUnitMaxAcceleration);
                    arriveAcceleration += inTunnelConeCheckConstant * coneCheck(currentSlot.character);
                    if (arriveAcceleration.magnitude > formationUnitMaxAcceleration)
                    {
                        arriveAcceleration = arriveAcceleration.normalized * formationUnitMaxAcceleration;
                    }
                    rb.velocity += arriveAcceleration;
                    if (rb.velocity.magnitude > formationUnitMaxVelocity)
                    {
                        rb.velocity = rb.velocity.normalized * formationUnitMaxVelocity;
                    }
                }
            }
            if (inTunnel)
            {
                if (Vector3.Distance(currentPosition, path [3].transform.position) < 0.2f)
                {
                    inTunnel    = false;
                    rb.velocity = Vector2.zero;


                    completedTunnel [unitInTunnelIndex] = true;
                    unitInTunnelIndex = closestBoidIndexToStartOfTunnel();
                    if (unitInTunnelIndex == -1)
                    {
                        goingThroughTunnel = false;
                        characterRadius   *= 2f;
                    }
                }
                else
                {
                    Vector2 arriveAcceleration = DynamicSeek(currentPosition, path [3].transform.position, formationUnitMaxAcceleration);

                    rb.velocity += arriveAcceleration;

                    if (rb.velocity.magnitude > formationUnitMaxVelocity)
                    {
                        rb.velocity = rb.velocity.normalized * formationUnitMaxVelocity;
                    }
                }
            }
            float angle = Mathf.Rad2Deg * Mathf.Atan2(-rb.velocity.x, rb.velocity.y);

            currentSlot.character.transform.eulerAngles = new Vector3(0, 0, angle);
        }
        else
        {
            foreach (SlotAssignment slot in slotAssignments)
            {
                Rigidbody2D rb = slot.character.GetComponent <Rigidbody2D> ();

                Vector3 position = slot.character.transform.position;
                Vector3 target   = pattern.getSlotLocation(slot.slotNumber).position + anchorPosition;
                Vector2 formationSeekAcceleration   = formationWeight * DynamicSeek(position, target, formationUnitMaxAcceleration);
                Vector2 formationArriveAcceleration = formationWeight * DynamicArrive(position, target, rb.velocity, formationUnitMaxVelocity, formationUnitMaxAcceleration);

                target = transform.position;

                Vector2 targetSeekAcceleration   = followWeight * DynamicSeek(position, target, formationUnitMaxAcceleration);
                Vector2 targetArriveAcceleration = followWeight * DynamicArrive(position, target, rb.velocity, formationUnitMaxVelocity, formationUnitMaxAcceleration);

                Vector2 coneCheckAcceleration = coneCheckConstant * coneCheck(slot.character);

                Vector2 acceleration = coneCheckAcceleration + formationSeekAcceleration + formationArriveAcceleration + targetSeekAcceleration + targetArriveAcceleration;

                if (acceleration.magnitude > formationUnitMaxAcceleration)
                {
                    acceleration = formationUnitMaxAcceleration * acceleration.normalized;
                }

                rb.velocity += acceleration;

                if (rb.velocity.magnitude > formationUnitMaxVelocity)
                {
                    rb.velocity = formationUnitMaxVelocity * rb.velocity.normalized;
                }

                float angle = Mathf.Rad2Deg * Mathf.Atan2(-rb.velocity.x, rb.velocity.y);

                slot.character.transform.eulerAngles = new Vector3(0, 0, angle);
            }
        }


        if (Vector3.Distance(this.transform.position, path[currentIndex].transform.position) < .5f)
        {
            if (currentIndex < path.Length - 1)
            {
                currentIndex++;
                if (currentIndex == 3)
                {
                    goingThroughTunnel = true;
                    unitInTunnelIndex  = closestBoidIndexToStartOfTunnel();
                    setFormationStop();
                    inTunnel = false;
                }
            }
            else
            {
                completed      = true;
                rbody.velocity = new Vector2(0, 0);
            }
        }



        if (currentIndex == 4 && goingThroughTunnel)
        {
            rbody.velocity = new Vector2(0, 0);
        }

        else if (!completed)
        {
            Vector2 leadAcceleration = Pathfind(transform.position);

            if (leadAcceleration.magnitude > leadUnitMaxAcceleration)
            {
                leadAcceleration = leadUnitMaxAcceleration * leadAcceleration.normalized;
            }

            rbody.velocity += leadAcceleration;

            if (rbody.velocity.magnitude > leadUnitMaxVelocity)
            {
                rbody.velocity = leadUnitMaxVelocity * rbody.velocity.normalized;
            }

            if (Vector3.Distance(transform.position, getAverageUnitPosition()) > maxDistanceConstant)
            {
                rbody.velocity *= 1 / Vector3.Distance(transform.position, getAverageUnitPosition());
            }
            float leadAngle = Mathf.Rad2Deg * Mathf.Atan2(-rbody.velocity.x, rbody.velocity.y);
            transform.eulerAngles = new Vector3(0, 0, leadAngle);
        }
    }