コード例 #1
0
    /*-------------------------------------------------------------------------------------------------------------*/

    /** <summary>
     * Updates the position and rotation of the boid based on the <see cref="VectorSet"/>. </summary>
     * <param name="direction_vector"> The vector used to update the boid's velocity </param> */
    public void Update_velocity(Vector3 direction_vector)
    {
        //calculate bird's new velocity based on the directionVector and the update time
        Vector3 new_velocity = rigidbody.velocity + (direction_vector + randomizer.Get_random_vector()) * Time.deltaTime;

        //apply a turn
        Quaternion target_rotation = Quaternion.LookRotation(new_velocity);

        transform.rotation = Quaternion.Lerp(transform.rotation, target_rotation, 30 * Time.deltaTime);

        //set the new velocity
        rigidbody.velocity = new_velocity;
    }