示例#1
0
    public void Walk(Vector3 target)
    {
        Vector3 movementModifier = new Vector3();
        float   rotationModifier = 0;

        //movementModifier += (nextPos - transform.position).normalized * mainMovementPriority;
        //movementModifier += transform.forward * mainMovementPriority;
        //rotationModifier += Vector3.SignedAngle(transform.forward, (nextPos - transform.position).normalized, Vector3.up);
        int rotationModAmount = 0;

        for (int i = 0; i < behaviours.Length; i++)
        {
            try
            {
                SteeringBehaviour sb = (SteeringBehaviour)behaviours[i];
                movementModifier += sb.CalculateMovement(new Vector3(target.x, transform.position.y, target.z));
                float rotationAmount = sb.CalculateRotation(target, rotationSpeed);
                if (Mathf.Abs(rotationAmount) != 0)
                {
                    rotationModifier += rotationAmount;
                    rotationModAmount++;
                }
            }
            catch
            {
                GroupBehaviour gb = (GroupBehaviour)behaviours[i];
                movementModifier += gb.CalculateMovement(group.Agents, this, new Vector3(target.x, transform.position.y, target.z));
                float rotationAmount = gb.CalculateRotation(group.Agents, rotationSpeed);
                if (Mathf.Abs(rotationAmount) != 0)
                {
                    rotationModifier += rotationAmount;
                    rotationModAmount++;
                }
            }
        }

        //Saco promedio o no? mmm...
        //rotationModifier /= rotationModAmount;

        movementModifier.Normalize();
        transform.RotateAround(transform.position, Vector3.up, Mathf.Sign(rotationModifier) * Mathf.Min(Mathf.Abs(rotationModifier), rotationSpeed) * rotationSpeed * Time.deltaTime);
        transform.position += movementModifier * movementSpeed * Time.deltaTime;
    }