Exemple #1
0
    void Update()
    {
        Vector3 my_pos             = transform.position;
        Vector3 tile_pos           = move.GetTargetPosition();
        Vector3 distance_to_target = new Vector3(Vector3.Zero);

        distance_to_target.x = tile_pos.x - my_pos.x;
        distance_to_target.z = tile_pos.z - my_pos.z;

        //Out of zone case
        if (distance_to_target.Length > slow_distance)
        {
            if (in_range == true)
            {
                in_range = false;
            }
            return;
        }
        //On slow zone case
        else if (distance_to_target.Length < slow_distance && distance_to_target.Length > min_distance)
        {
            Vector3 ideal_velocity = distance_to_target.Normalized * move.GetMaxVelocity() * (distance_to_target.Length / slow_distance);
            Vector3 deceleration   = (ideal_velocity - move.GetCurrentVelocity());

            if (deceleration.Length > move.GetMaxAcceleration())
            {
                deceleration = deceleration.Normalized * move.GetMaxAcceleration();
            }

            deceleration = deceleration + distance_to_target.Normalized * move.GetMaxAcceleration() * (-1);

            move.Accelerate(deceleration);
        }
    }
    void Update()
    {
        Vector3 acceleration = new Vector3(Vector3.Zero);
        Vector3 target_pos   = move.GetTargetPosition();
        Vector3 pos          = trans.position;

        acceleration.x = target_pos.x - pos.x;
        acceleration.z = target_pos.z - pos.z;

        acceleration = acceleration.Normalized * move.GetMaxAcceleration();

        move.Accelerate(acceleration);
    }