Example #1
0
    private Vector3 Arrive()
    {
        Vector3 accel = steeringBasics.Arrive(resourceObject.transform.position, this);

        if (accel == Vector3.zero)
        {
            resourceObject.resourceHealth -= Time.deltaTime;
            drone.HealthRegen();
        }
        return(accel);
    }
    // Update is called by a TailManager once each frame
    public void CustomUpdate(float minDistance)
    {
        if (_mBodyTarget != null)
        {
            Vector3 look = _mBodyTarget.GetTailPosition() - transform.position;
            transform.rotation = Quaternion.LookRotation(look, Vector3.up);

            if ((transform.position - _mBodyTarget.GetTailPosition()).magnitude > minDistance)
            {
                //transform.position = _mBodyTarget.GetTailPosition( ) - transform.forward * 0.5f;
                transform.position += Steering.Arrive(_mBodyTarget.GetTailPosition(), transform.position, 5, 50);
            }
        }
        else if (_mTarget != null)
        {
            Vector3 look = _mTarget.position - transform.position;
            transform.rotation = Quaternion.LookRotation(look, Vector3.up);

            if ((transform.position - _mTarget.position).magnitude > minDistance)
            {
                //transform.position = _mTarget.position - transform.forward * followDistance;
                Vector3 spacer = _mTarget.position + ((transform.position - _mTarget.position).normalized);
                transform.position += Steering.Arrive(spacer, transform.position, 5, 50);
            }
        }
    }
    public Vector3 GetSteeringCohesion(ICollection <GameObject> targets)
    {
        Vector3     centerOfMass = Vector3.zero;
        int         count        = 0;
        Rigidbody2D rb2D;

        /* Sums up everyone's position who is close enough and in front of the character */
        foreach (GameObject r in targets)
        {
            rb2D = r.GetComponent <Rigidbody2D>();
            Vector3 rbPos = rb2D.position;
            if (steeringBasics.IsFacing(rbPos, cohFacingCosineVal))
            {
                centerOfMass += rbPos;
                count++;
            }
        }

        if (count == 0)
        {
            return(Vector3.zero);
        }
        else
        {
            centerOfMass = centerOfMass / count;

            return(steeringBasics.Arrive(centerOfMass, mb));
        }
    }
Example #4
0
    /// <summary>
    /// Path Following
    /// </summary>
    public static Vector2 PathFollowing(Vehicle agent, List <Vector2> path, float maxDistance, float decelerationDist, bool loop = false)
    {
        int index = 0;

        currentPoint.TryGetValue(agent, out index);

        if ((agent.position - path[index]).sqrMagnitude < Mathf.Pow(maxDistance, 2) && index < path.Count - 1)
        {
            index++;
        }

        if (!loop && index == path.Count - 1)
        {
            currentPoint[agent] = index;
            return(Steering.Arrive(agent, Vehicle.CreateVirtualVehicle(path[index]), decelerationDist));
        }

        if (loop && index == path.Count)
        {
            index = 0;
        }

        currentPoint[agent] = index;

        return(Steering.Seek(agent, Vehicle.CreateVirtualVehicle(path[index])));
    }
Example #5
0
    public Vector3 FollowPath()
    {
        if (m_Path.Count == 0)
        {
            return(Vector3.zero);
        }

        if ((transform.position - m_Path[0].transform.position).magnitude < m_WaypointSensitivity)
        {
            m_Path.RemoveAt(0);
            m_Path.TrimExcess();
        }

        if (m_Path.Count != 0)
        {
            Debug.DrawLine(transform.position, m_Path[0].transform.position, Color.red);
        }

        if (m_Path.Count > 1)
        {
            for (int i = 0; i < m_Path.Count - 1; i++)
            {
                Debug.DrawLine(m_Path[i].transform.position, m_Path[i + 1].transform.position, Color.red);
            }
            FindDestintation();
            return(Steering.Seek(m_Path[0].transform.position, transform.position, m_Speed));
        }
        FindDestintation();
        return(Steering.Arrive(m_Path[0].transform.position, transform.position, m_Speed, m_SteeringSensitivity));
    }
Example #6
0
 public override Vector2 CalculateSteering(Vehicle agent, List <Vehicle> targets)
 {
     if (targets.Count == 0)
     {
         return(Vector2.zero);
     }
     else
     {
         return(Steering.Arrive(agent, targets[0], deceleration));
     }
 }
    public override Vector2 CalculateSteering(Vehicle agent, List <Vehicle> targets)
    {
        List <Vehicle> neighbors = new List <Vehicle>();

        foreach (Vehicle v in Vehicle.AllVehicles)
        {
            if (v != agent && (v.position - agent.position).magnitude < neighborRadius)
            {
                neighbors.Add(v);
            }
        }

        Vector2 separation = Steering.Separation(agent, neighbors);
        Vector2 arrive     = Steering.Arrive(agent, targets[0], 0.6f);

        return(separation * 3f + arrive);
    }
        public void Execute(int index)
        {
            Steering steering = new Steering();

            steering.MaxSpeed = MaxArriveSpeed;
            float2 sourcePos = new float2(SmallControllerPos[index].Value.x, SmallControllerPos[index].Value.y);
            float2 sourceVel = Velocities[index].Velocity;

            float2 targetPos      = GetTargetPos(sourcePos);
            float2 desireVelosity = steering.Arrive(sourcePos, targetPos, SlowingRadius);

            VelocityData data = new VelocityData();

            data.MaxSpeed     = MaxSpeed;
            data.Velocity     = desireVelosity;
            Velocities[index] = data;
        }
Example #9
0
    private void Update()
    {
        Vector3 position   = transform.position;
        Vector3 target     = targetPos.position;
        bool    isSteering = GlobalSettings.isInSteering;

        if (rb.velocity.magnitude <= slowSpeed)
        {
            // print("we slow");
            // A
            if (Vector3.Distance(position, target) <= closeDistance)
            {
                // print("we close");
                //A i) behaviour

                //move to target, no turning
                if (!isSteering)
                {
                    Kinematic.Arrive(rb, transform, targetPos.position, closeSpeed);
                }
                else
                {
                    Steering.Arrive(rb, transform, targetPos.position, closeAcceleration, closeSpeed);
                }
            }
            else
            {
                // print("we far");
                //A ii) behaviour

                //if angle btw forward and target close to 0,
                if (Vector3.Angle(transform.forward, target - position) <= 2f)
                {
                    // then move forward
                    if (!isSteering)
                    {
                        Kinematic.Arrive(rb, transform, targetPos.position, farSpeed);
                    }
                    else
                    {
                        Steering.Arrive(rb, transform, targetPos.position, farAcceleration, farSpeed);
                    }
                }
                else
                {
                    // else turn towards target
                    if (isSteering || rb.velocity.magnitude < 1f)
                    {
                        Helper.Alignment(transform, target - position, stopRotationSpeed);
                    }
                    else
                    {
                        Helper.Alignment(transform, rb.velocity, stopRotationSpeed);
                    }
                }
            }
        }
        else
        {
            // print("we fast");
            //B
            // check arc infront of character
            float coneAngle = Helper.Map(rb.velocity.magnitude, 0f, farSpeed, fastAngle, slowAngle);
            if (Vector3.Angle(transform.forward, target - position)
                <= coneAngle)
            {
                // print("OhISee");
                //B i)
                if (!isSteering)
                {
                    Kinematic.Arrive(rb, transform, targetPos.position, farSpeed);
                }
                else
                {
                    Steering.Arrive(rb, transform, targetPos.position, farAcceleration, farSpeed);
                }
                Helper.Alignment(transform, rb.velocity, moveRotationSpeed);
            }
            else
            {
                // print("OhImBlind");
                // B ii)
                rb.velocity = Vector3.zero; //stop
                Helper.Alignment(transform, target - position, stopRotationSpeed);
            }
        }
    }
Example #10
0
    // Update is called once per frame
    void LateUpdate()
    {
        if (m_Behaviour == BossBehaviourType.ENEMY_BEHAVIOUR.ATTACK && !superAttackReady)
        {
            superAttackTimer += 1.0f * Time.deltaTime;
            //Debug.Log("super attack timer: " + superAttackTimer);
        }

        if (m_Behaviour == BossBehaviourType.ENEMY_BEHAVIOUR.RETREAT && !throwObjectReady)
        {
            throwObjectTimer += 1.0f * Time.deltaTime;

            if (throwObjectReady)
            {
                throwObjectReady = false;
                throwObjectTimer = 0.0f;
                Debug.Log("boss is throwing object");
            }
        }

        //reset attacking timer so the enemy wont attack constatly.
        if (m_attacking == true)
        {
            attackTimer += 1.0f * Time.deltaTime;
        }

        if (m_attacking && attackTimer > attackDelay)
        {
            attackTimer = 0.0f;
        }

        if (superAttackTimer > superAttackDelay)
        {
            superAttackReady = true;
            superAttackTimer = 0.0f;
            //Debug.Log("super attack timer: " + superAttackTimer);
        }

        if (throwObjectTimer > throwObjectDelay)
        {
            throwObjectReady = true;
            throwObjectTimer = 0.0f;
        }

        if (m_Health.GetHealthPoints() <= 0)
        {
            return;
        }
        Vector3 moveBy = Vector3.zero;

        if ((transform.position - m_CurrentTarget.transform.position).magnitude > 0.5f)
        {
            int count = m_Path.Count - 1;
            if (m_Path.Count == 0 || m_Path[count] != m_CurrentTarget)
            {
                m_Path = PathFinding.DumbSearch.findPath(transform.position, m_CurrentTarget.transform.position);
            }
            moveBy += FollowPath();
        }
        else
        {
            UpdateState();
            UpdateNavigationTarget();
            moveBy = Steering.Arrive(m_CurrentTarget.transform.position, transform.position, m_Speed, m_SteeringSensitivity);
        }

        transform.position += moveBy * Time.deltaTime;
    }