Exemple #1
0
    private void Attack()
    {
        var target = HerbivoreSensor.Closest.gameObject ?? ClosestSnatcher;

        if (target == null)
        {
            return;
        }

        //Carnivores move faster at certain parts of the day
        var speed = (DayClock.Singleton.Hour > HuntingPeriodStart && DayClock.Singleton.Hour < HuntingPeriodEnd)
            ? HuntingPeriodSpeed
            : BaseSpeed;

        var vel = Steering.Pursuit(gameObject, target, speed);

        if (vel.sqrMagnitude < .2f)
        {
            vel = transform.forward;
        }

        //Don't do any smoothing of the rotation, just set it directly. Avoids constant missing
        transform.rotation = Quaternion.LookRotation(vel, transform.up);

        if (!m_Attacking && (FoodPosition.position - target.transform.position).sqrMagnitude < 5f)
        {
            m_Attacking = true;
            m_AnimAudioController.DoAttack();
        }
    }
    private void Attack()
    {
        var target = HerbivoreSensor.Closest.gameObject ?? ClosestSnatcher;

        if (target == null)
        {
            return;
        }

        //Carnivores move faster at certain parts of the day
        var speed = GetSpeed();

        var vel = Steering.Pursuit(gameObject, target, speed);

        if (vel.sqrMagnitude < .2f)
        {
            vel = transform.forward;
        }

        transform.rotation = Quaternion.RotateTowards(transform.rotation, Quaternion.LookRotation(vel, transform.up), 1f);

        if (ApplyVelocity)
        {
            Rigidbody.velocity = vel.normalized * speed;
        }

        if (!m_Attacking && (FoodPosition.position - target.transform.position).sqrMagnitude < 10f)
        {
            m_Attacking = true;
            m_AnimAudioController.DoAttack();
        }
    }
Exemple #3
0
 public override Vector2 CalculateSteering(Vehicle agent, List <Vehicle> targets)
 {
     if (targets.Count == 0)
     {
         return(Vector2.zero);
     }
     else
     {
         return(Steering.Pursuit(agent, targets[0], predictTweaker));
     }
 }
Exemple #4
0
    private void CalcSteeringForce()
    {
        steeringForce = Vector3.zero;

        //Keeps werewolves away from Villager Spawn point
        steeringForce += gameManager.avoidWt * steering.AvoidObstacle(respawnPont, 100f);


        float mayDist = Vector3.Distance(this.transform.position, gameManager.Mayor.transform.position);

        //Choose new villager to chase (closest villager)
        target = gameManager.Villagers[0];
        findTarget();

        float tarDist = Vector3.Distance(this.transform.position, target.transform.position);

        if (tarDist > 30)
        {
            steeringForce += 10 * steering.Pursuit(target.transform.forward +
                                                   target.transform.position);
        }
        else
        {
            steeringForce += 6 * steering.Seek(target);
        }

        if (mayDist < 20)
        {
            steeringForce += 20 * steering.Flee(gameManager.Mayor);
        }
        else
        {
            steeringForce += 5 * steering.Evasion(gameManager.Mayor.transform.forward +
                                                  gameManager.Mayor.transform.position);
        }

        //avoid close obstacles
        for (int i = 0; i < gameManager.Obstacles.Length; i++)
        {
            if (Vector3.Distance(this.transform.position, gameManager.Obstacles[i].transform.position) < 60)
            {
                steeringForce += gameManager.avoidWt * steering.AvoidObstacle(gameManager.Obstacles[i], gameManager.avoidDist);
            }
        }
    }
Exemple #5
0
        void ICmpUpdatable.OnUpdate()
        {
            var ship      = GameObj.GetComponent <Ship>();
            var body      = GameObj.GetComponent <RigidBody>();
            var targetPos = Target.Transform.Pos.Xy;

            _elapsedTime += Time.TimeMult;

            var thrustVector = Steering.Pursuit(GameObj.Transform, Target.Transform);

            ship.ThrustVector = thrustVector;

            if (thrustVector.LengthSquared > 0)
            {
                var angle = Utilities.FindAngleBetweenTwoVectors(ship.CurrentDirection, thrustVector);
                var limit = MathF.DegToRad(5);
                if (angle > limit)
                {
                    ship.TurnDirection = Rotation.CCW;
                }
                else if (angle < -limit)
                {
                    ship.TurnDirection = Rotation.CW;
                }
                else
                {
                    if (Math.Abs(angle) < limit) // damp rotation if we are close to desired facing
                    {
                        body.AngularVelocity *= 0.9f;
                    }
                }
            }

            /*
             * if (components.IsValid)
             * {
             *  //_vehicle.Ship.ThrustVector = (components.SteeringForce + _vehicle.Velocity).Normalized * components.Thrust;
             *
             *  if (components.Rotation < 0)
             *      _vehicle.Ship.TurnDirection = Rotation.CW;
             *  else if (components.Rotation > 0)
             *      _vehicle.Ship.TurnDirection = Rotation.CCW;
             *
             * }*/
        }
    private void Attack()
    {
        var target = HerbivoreSensor.Closest.gameObject ?? ClosestSnatcher;

        if (target == null)
        {
            return;
        }

        if (m_Roaring)
        {
            Rigidbody.velocity = Vector3.zero;
            transform.LookAt(target.transform);
            return;
        }

        //Carnivores move faster at certain parts of the day
        var speed = (DayClock.Singleton.Hour > HuntingPeriodStart && DayClock.Singleton.Hour < HuntingPeriodEnd)
            ? HuntingPeriodSpeed
            : BaseSpeed;

        if (m_DiveBombing)
        {
            speed *= 2f;
        }

        var vel = Steering.Pursuit(gameObject, target, speed);

        if (vel.sqrMagnitude < .2f)
        {
            vel = transform.forward;
        }

        //Use velocity so that physics continues to work
        transform.rotation = Quaternion.RotateTowards(transform.rotation, Quaternion.LookRotation(vel, transform.up), 5f);
    }
Exemple #7
0
        void ICmpUpdatable.OnUpdate()
        {
            var ship = ControlledShip;
            var body = GameObj.GetComponent <RigidBody>();

            if (Target == null)
            {
                return;
            }

            var targetPos = Target.Transform.Pos.Xy;

            _elapsedTime += Time.TimeMult;

            var thrustVector = Steering.Pursuit(GameObj.Transform, Target.Transform);
            var turnVector   = thrustVector;

            ship.ThrustVector = thrustVector + (Steering.Flee(GameObj.Transform.Pos.Xy, GameObj.Transform.GetWorldPoint(_evadeVector)) * 100);

            if (turnVector.LengthSquared > 0)
            {
                var   fps          = Time.Fps <= 0 ? 60 : Time.Fps;
                float desiredAngle = MathF.NormalizeAngle(turnVector.Angle);
                //var angle = Utilities.FindAngleBetweenTwoVectors(ship.CurrentDirection, turnVector);
                float nextAngle     = ship.GameObj.Transform.Angle + body.AngularVelocity / fps;
                float totalRotation = desiredAngle - nextAngle;

                //while (totalRotation < -MathF.Pi) totalRotation += MathF.TwoPi;
                //while (totalRotation > MathF.Pi) totalRotation -= MathF.TwoPi;


                float desiredAngularVelocity = totalRotation * fps;
                float torque = body.Inertia * (body.AngularDamping + 1) + desiredAngularVelocity / (1 / fps);

                ship.DesiredTorque = torque;

                /*
                 * var limit = MathF.DegToRad(RotationDampingAngle);
                 * if (angle > limit)
                 *  ship.TurnDirection = Rotation.CCW;
                 * else if(angle < -limit)
                 *  ship.TurnDirection = Rotation.CW;
                 * else
                 * {
                 *  if (Math.Abs(angle) < limit) // damp rotation if we are close to desired facing
                 *      body.AngularVelocity *= RotationDamping;
                 * }
                 */
            }

            GameObj.Transform.Pos   = ship.GameObj.Transform.Pos;
            GameObj.Transform.Angle = ship.GameObj.Transform.Angle;

            /*
             * if (components.IsValid)
             * {
             *  //_vehicle.Ship.ThrustVector = (components.SteeringForce + _vehicle.Velocity).Normalized * components.Thrust;
             *
             *  if (components.Rotation < 0)
             *      _vehicle.Ship.TurnDirection = Rotation.CW;
             *  else if (components.Rotation > 0)
             *      _vehicle.Ship.TurnDirection = Rotation.CCW;
             *
             * }*/
        }