Example #1
0
    private void changeDirection()
    {
        if (flyingRoute != null && flyingDirection != flyingRoute.transform.position)
        {
            // find out the angle of the axis

            flyingDirection = flyingRoute.transform.position;

            Vector3 heading = flyingDirection - transform.position;

            // Get a copy of your forward vector

            //transform.Rotate(heading.normalized);
            //transform.rotation = transform.rotation*heading; //Quaternion.Slerp(transform.rotation,heading,1f);
            //GetComponent<Rigidbody> ().velocity=Vector2.zero;
            Rigidbody rigidbody = GetComponent <Rigidbody> ();          //.velocity = heading.normalized * Random.Range (10.0f, 30.0f);
            rigidbody.velocity = heading.normalized * Random.Range(GameParams.instance().minDuckSpeed, GameParams.instance().maxDuckSpeed);

            //Vector3 forward = transform.forward;
            // Zero out the y component of your forward vector to only get the direction in the X,Z plane
            heading.y             = 0;
            transform.eulerAngles = Quaternion.LookRotation(heading).eulerAngles;
            //float headingAngle = Quaternion.LookRotation(forward).eulerAngles.y;

            //transform.Rotate(Vector3.zero);
            //transform.Rotate(new Vector3(0,headingAngle,0));
        }
    }
 void Start()
 {
     locationChangeRate = GameParams.instance().flyRouteRate;
 }