示例#1
0
 public void Initialize()
 {
     _rb = GetComponent <Rigidbody2D>();
     _followBehaviour = new SteeringBehaviour(_rb, _steeringData);
     _moveActive      = true;
     SetMovementType(_type);
 }
示例#2
0
    // Calculates all forces from attached SteeringBehaviours
    void ComputeForces()
    {
        // Reset force before calculation
        force = Vector3.zero;

        // Loop through all behaviours
        for (int i = 0; i < behaviours.Count; i++)
        {
            // Get current behaviour
            SteeringBehaviour b = behaviours[i];

            // Check if behaviour is active and enabled
            if (!b.isActiveAndEnabled)
            {
                // Skip over to next behaviour
                continue;
            }

            // Apply behaviour's force to our final force
            force += b.GetForce() * b.weighting;

            // Check if force has gone over maxSpeed
            if (force.magnitude > maxSpeed)
            {
                // Cap the force down to maxSpeed
                force = force.normalized * maxSpeed;

                // Exit for loop
                break;
            }
        }
    }
    /// <summary>
    /// the requester must have an target for this to work as intended
    /// </summary>
    protected Vector2 ApplyAvoidance(AIAgent requester, Vector2 requesterPosition, Vector2 currentDesiredPostion, bool linearWeight, int anglesRangeToIgnore)
    {
        Vector2 des = requester.Destination;
        Vector2?avoidanceTemp;
        AIAgent avoidanceObj;


        if (perpendicular)
        {
            avoidanceTemp = SteeringBehaviour.ObstacleAvoidance(requester, requesterPosition,
                                                                (currentDesiredPostion - requesterPosition).normalized, out avoidanceObj);
        }

        else
        {
            avoidanceTemp = SteeringBehaviour.ObstacleAvoidance(requester, requesterPosition, out avoidanceObj);
        }



        if (UseObstacleAvoidance(requester, avoidanceTemp, avoidanceObj, des, anglesRangeToIgnore))
        {
            float avoidanceWeight = GetAvoidanceWeight(requester, requesterPosition, avoidanceObj.transform.position, linearWeight);
            currentDesiredPostion = Vector2.Lerp(currentDesiredPostion, avoidanceTemp.Value, avoidanceWeight * requester.data.aviodanceWieghtMultiplier);
        }
        return(currentDesiredPostion);
    }
示例#4
0
 public Attack(GameObject agent, GameObject enemy) : base(agent, TaskType.Attack)
 {
     this.enemy            = enemy;
     steeringBehaviour     = agent.GetComponent <SteeringBehaviour>();
     stats                 = agent.GetComponent <Stats>();
     remainingCooldownTime = 0.0f;
 }
示例#5
0
    private void Awake()
    {
        steering = new SteeringBehaviour(this);
        InitVehicle(VehiclePrefab, WeaponPrefab, transform.position, transform.rotation);

        SetNoTargetState();
    }
示例#6
0
    public void EnableFollowPlayer()
    {
        // Change body color to blue
        renderer.GetPropertyBlock(propBlock);
        propBlock.SetColor("_Color", new Color(0, 0, 1, 1));
        renderer.SetPropertyBlock(propBlock, 0);

        // Set behaviour to follow player trail and set followtarget
        behaviour = SteeringBehaviour.Follow;
        fleeTimer = minFleeSeconds;

        if (!PlayerController.Instance.minionTrail.Contains(gameObject))
        {
            PlayerController.Instance.minionTrail.Add(gameObject);
        }

        if (PlayerController.Instance.minionTrail[0] == this.gameObject)
        {
            followTarget = PlayerController.Instance.transform;
        }
        else
        {
            int index = PlayerController.Instance.minionTrail.IndexOf(gameObject);
            followTarget = PlayerController.Instance.minionTrail[index - 1].transform;
        }
    }
示例#7
0
 public DynamicObstacleAvoidance(float _avoidDistance, float _lookahead, SteeringBehaviour _s, float _maxAcceleration)
 {
     avoidDistance   = _avoidDistance;
     lookahead       = _lookahead;
     s               = _s;
     maxAcceleration = _maxAcceleration;
 }
示例#8
0
 public DynamicPathFollowing(Path _path, float _pathOffset, Transform _currentParam, SteeringBehaviour _s)
 {
     path         = _path;
     pathOffset   = _pathOffset;
     currentParam = _currentParam;
     s            = _s;
 }
示例#9
0
    void ComputeForces()
    {
        // SET force to zero
        force = Vector3.zero;

        // FOR i := 0 to behaviours count
        for (int i = 0; i < behaviours.Count; i++)
        {
            // IF behavior is enabled
            SteeringBehaviour behaviour = behaviours[i];
            if (!behaviour.enabled)
            {
                continue;
            }

            // SET force to force + behaviour force
            force += behaviour.GetForce() * behaviour.weighting;

            // IF force is greater than maxVelocity
            if (force.magnitude > maxVelocity)
            {
                // SET force to force normalized x maxVelocity
                force = force.normalized * maxVelocity;
                // BREAK
                break;
            }
        }
    }
示例#10
0
    private void Update()
    {
        _direction += SteeringBehaviour.Seek(TargetPosition, _rb.velocity, this) * Time.deltaTime;
        _direction  = SteeringBehaviour.Arriving(this, _direction, TargetPosition, distanceToArriveAtTargetLocation, 0.6f);
        //_movement.MoveTowards(_rb, TargetPosition, Time.deltaTime);

        _movement.AssignVelocity(_rb, Vector3.ClampMagnitude(_direction, _maxSpeed));

        if (rotateForwardToDirection)
        {
            //var rotation = Quaternion.identity;
            _rb.transform.LookAt(_movement.LastDirectionFacing + _rb.position, Vector3.up);
            var newRotation = _rb.transform.rotation;
            if (lockRotationX)
            {
                newRotation.x = 0;
            }
            if (lockRotationY)
            {
                newRotation.y = 0;
            }
            if (lockRotationZ)
            {
                newRotation.z = 0;
            }

            _rb.transform.rotation = newRotation;
        }

        Debug.DrawLine(_rb.transform.position, _movement.LastDirectionFacing + _rb.transform.position, Color.blue);
    }
示例#11
0
    void ComputeForces()
    {
        // reset the force
        force = Vector3.zero;

        //Loop through all behaviours attached to gameobject
        for (int i = 0; i < behaviours.Count; i++)
        {
            SteeringBehaviour behaviour = behaviours[i];
            if (!behaviour.isActive)
            {
                continue;
            }


            // Calculate the force from it
            force += behaviour.GetForce() * behaviour.weighting;

            //If the force are too big
            if (force.magnitude > maxVelocity)
            {
                //Clamp it to the nax
                force = force.normalized * maxVelocity;
                //stop calculating
                break;
            }
        }
    }
示例#12
0
 void ComputeForces()
 {
     // SET force to zero
     force = Vector3.zero; // When you create a variable in a function,
                           // It only exists within that function.
                           // FOR i = 0 to behaviours length
     for (int i = 0; i < behaviours.Length; i++)
     {
         SteeringBehaviour behaviour = behaviours[i];
         // IF behaviour is not enabled
         if (!behaviour.enabled)
         {
             // CONTINUE
             continue;
         }
         // SET force to force + behaviour's force
         force += behaviour.GetForce();
         // IF force is greater than maxVelocity
         if (force.magnitude > maxVelocity)
         {
             // SET force to force normalized x maxVelocity
             force = force.normalized * maxVelocity;
             // BREAK
             break;
         }
     }
 }
示例#13
0
    void ComputeForces()
    {
        // SET force to zero
        force = Vector3.zero;

        // FOR i = 0 to behaviours count
        for (int i = 0; i < behaviours.Length; i++)
        {
            SteeringBehaviour behaviour = behaviours[i];
            // IF behaviour is not enabled
            if (!behaviour.enabled)
            {
                // CONTINUE
                continue;
            }
            // SET force to force + behaviour's force
            force += behaviour.GetForce();
            // IF force is greater than maxVelocity
            if (force.magnitude > maxVelocity)
            {
                // SET force to force normalized x maxVelocity
                force = force.normalized * maxVelocity;
                // BREAK
                break;
            }
        }
    }
示例#14
0
    public void SummonObject(Vector3 summonPosition)
    {
        SteeringBehaviour holderSummon = Instantiate(summonableObject, summonPosition, Quaternion.identity).GetComponent <SteeringBehaviour>();

        holderSummon.followTransform = this.transform;
        holderSummon.isAutomated     = true;
    }
示例#15
0
        public override void Update(float timeElapsed)
        {
            // First step calculate steering force
            Vector2D steeringForce = this.SB.Calculate();

            // If the ObstacleAvoidance returns something that is not null. overrule the steeringforce.
            this.SB = new ObstacleAvoidance(this);
            Vector2D _avoidance = this.SB.Calculate();

            if (_avoidance != null)
            {
                steeringForce = _avoidance;
            }

            // Second step divide by the mass of the moving entity
            Vector2D Acceleration = steeringForce.Divide(this.Mass);

            // add the acceleration to the velocity (multiply by timeElapsed)
            this.Velocity.Add(Acceleration.Multiply(timeElapsed));
            // truncate the velocity back to regular speeds
            this.Velocity.truncate(this.MaxSpeed);
            // update the current position;
            this.Pos.Add(this.Velocity);

            Console.WriteLine(ToString());
        }
示例#16
0
 private void actuadorHumanoNoDriftin()
 {
     if (selectedBehaviour != antiDorifto)
     {
         this.velocidad = Vector3.zero;
         antiDorifto    = selectedBehaviour;
     }
 }
示例#17
0
 public void addSteeringBehaviour(SteeringBehaviour behaviour, float weight)
 {
     weights.Add(new SteeringWeight()
     {
         weight = weight, behaviourName = behaviour.getName()
     });
     behaviours.Add(behaviour);
 }
示例#18
0
文件: AgentNPC.cs 项目: fylux/GameAI
 public void RemoveSteering(SteeringBehaviour steer)
 {
     if (steers.Contains(steer))
     {
         steers.Remove(steer);
         Destroy(steer);
     }
 }
示例#19
0
文件: Vehicle.cs 项目: gjtqiyue/AI
 // Use this for initialization
 void Awake()
 {
     my_SteeringBehaviour = GetComponent <SteeringBehaviour>();
     my_SteeringBehaviour.SetVehicle(this);
     rig             = GetComponent <Rigidbody>();
     boxCollider     = GetComponent <BoxCollider>();
     taggedObstacles = new List <GameObject>();
 }
示例#20
0
    private void Awake()
    {
        steering = new SteeringBehaviour(this);
        InitVehicle(VehiclePrefab, WeaponPrefab, transform.position, transform.rotation);

        SetNoTargetState();

        speechCooldown = Random.Range(minSpeechTime, maxSpeechTime);
    }
示例#21
0
    internal override void newTaskLowWA(SteeringBehaviour st)
    {
        kinetic.Clear();
        WallAvoidance3WhiswersSD wall = new WallAvoidance3WhiswersSD();

        wall.mult = 0.5f;
        kinetic.Add(wall);
        kinetic.Add(st);
    }
示例#22
0
 void Awake()
 {
     playerHealth    = GameObject.FindGameObjectWithTag("Player").GetComponent <PlayerHealth> ();
     playerTransform = GameObject.FindGameObjectWithTag("Player").GetComponent <Transform>();
     anim            = GetComponent <Animator>();
     dogTransform    = GetComponent <Transform> ();
     rdb2            = GetComponent <Rigidbody2D> ();
     seek            = ScriptableObject.CreateInstance("SteeringBehaviour") as SteeringBehaviour;
 }
示例#23
0
 void Awake()
 {
     playerHealth   = GameObject.FindGameObjectWithTag("Player").GetComponent <PlayerHealth> ();
     waypoint1      = GameObject.Find("Waypoint7").GetComponent <Transform> ();
     waypoint2      = GameObject.Find("Waypoint8").GetComponent <Transform> ();
     helliTransform = GetComponent <Transform> ();
     rdb2           = GetComponent <Rigidbody2D> ();
     seek           = ScriptableObject.CreateInstance("SteeringBehaviour") as SteeringBehaviour;
 }
示例#24
0
    private void OnDestroy()
    {
        //Debug.Log("ActorMover Destroy :" + gameObject.name);
        GameWorld.instance.RemoveAgent(aiAgent);

        aiAgent            = null;
        steeringBehaviour  = null;
        m_pHeadingSmoother = null;
    }
示例#25
0
 void Awake()
 {
     player        = GameObject.FindGameObjectWithTag("Player").GetComponent <Transform> ();
     playerHealth  = player.GetComponent <PlayerHealth> () as PlayerHealth;
     rdb           = GetComponent <Rigidbody2D> ();
     guardCollider = GetComponent <BoxCollider2D>();
     anim          = GetComponent <Animator> ();
     seek          = ScriptableObject.CreateInstance("SteeringBehaviour") as SteeringBehaviour;
 }    //Awake
示例#26
0
    internal override void addTask(SteeringBehaviour st)
    {
        List <SteeringBehaviour> newTasks = new List <SteeringBehaviour>();

        newTasks.Add(new WallAvoidance3WhiswersSD());
        newTasks.Add(st);
        newTasks.AddRange(kinetic.GetRange(1, kinetic.Count - 1));
        kinetic.Clear();
        kinetic = new List <SteeringBehaviour>(newTasks);
    }
示例#27
0
 public void AddBehaviours(SteeringBehaviour steeringBehaviour)
 {
     if (_steeringBehaviours == null)
     {
         SetBehaviour(steeringBehaviour);
     }
     else
     {
         _steeringBehaviours.Add(steeringBehaviour);
     }
 }
示例#28
0
    void UpdateArrival()
    {
        var leaderPos = (Vector2)leader.transform.position;

        var leaderDir = SteeringBehaviour.GetDirection(leader);

        var arrivalTarget = leaderPos - leaderDir * behindDistance;

        arrival.enabled = true;
        arrival.SetTarget(arrivalTarget);
    }
示例#29
0
    public RandomRoam() : base(new SteeringBehaviour())
    {
        SteeringBehaviours = new SteeringBehaviour {
            EnableObjectAvoidance = true,
            EnableWallAvoidance   = true,
            Seek   = true,
            Wander = false
        };

        Navigation = new AStar();
    }
 void Awake()
 {
     girlTransform   = GetComponent <Transform> ();
     girlRigidBody   = GetComponent <Rigidbody2D> ();
     anim            = GetComponent <Animator> ();
     playerTransform = GameObject.FindGameObjectWithTag("Player").GetComponent <Transform> ();
     playerHealth    = playerTransform.GetComponent <PlayerHealth> () as PlayerHealth;
     pathPoints      = GameObject.Find("Pathpoints").GetComponentsInChildren <Transform> ();
     controlPoints   = GameObject.Find("Points").GetComponentsInChildren <Transform> ();
     seek            = ScriptableObject.CreateInstance("SteeringBehaviour") as SteeringBehaviour;
 }    //Awake
    // unity methods
    void Start()
    {
        moving = false;
        grounded = true;
        previously_grounded = true;

        movement_direction = Vector3.zero;

        body = GetComponent<Rigidbody>();
        movement = GetComponent<SteeringBehaviour>();
        original_max_speed = movement.max_speed;
    }
示例#32
0
    private void Awake()
    {
        steering = new SteeringBehaviour(this);
        InitVehicle(VehiclePrefab, WeaponPrefab, transform.position, transform.rotation);

        SetNoTargetState();
    }
示例#33
0
 public void AddBehaviour(SteeringBehaviour b)
 {
     behaviours.Add(b);
 }
示例#34
0
 public void RemoveBehaviour(SteeringBehaviour b)
 {
     behaviours.Remove(b);
 }
示例#35
0
    private void Awake()
    {
        steering = new SteeringBehaviour(this);
        InitVehicle(VehiclePrefab, WeaponPrefab, transform.position, transform.rotation);

        SetNoTargetState();

        speechCooldown = Random.Range(minSpeechTime, maxSpeechTime);
    }
 // Use this for initialization
 void Start()
 {
     m_velocity = getAngle();
     m_steering = new SteeringBehaviour();
 }
示例#37
0
 public void removeSteeringBehaviour(SteeringBehaviour behaviour)
 {
     steeringBehaviours.Remove(behaviour);
 }
示例#38
0
 // Core functions
 public void addSteeringBehaviour(SteeringBehaviour behaviour)
 {
     steeringBehaviours.Add (behaviour);
 }