コード例 #1
0
    /*
     *	Moves and rotates the ghost fish, the distance measure, and the moving distance bar.
     */
    public void PointJumpIndicators(int layerMask)
    {
        // if objects are hidden, make them visible
        if (!active)
        {
            StartIndicators();
        }

        RaycastHit hit;
        Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);

        if (Physics.Raycast(ray, out hit, Mathf.Infinity, layerMask))
        {
            // GHOST FISH
            // move the ghost fish to where the real fish is
            fishKinematic.transform.position = new Vector3(transform.position.x, transform.position.y + 0.15f, transform.position.z);

            // make the ghost fish look toward the point
            float   lookY  = fishKinematic.gameObject.transform.position.y;
            Vector3 lookAt = new Vector3(hit.point.x, lookY, hit.point.z);              // the ghost fish will look on its own y level
            fishKinematic.transform.LookAt(lookAt);

            // store its current rotation for the distance measure and bar
            float      degrees      = fishKinematic.gameObject.transform.rotation.eulerAngles.y;
            Quaternion flatRotation = Quaternion.Euler(0, degrees, 0);

            // finally, rotate the fish by 90 degrees so its head faces forward
            Quaternion rotate90 = Quaternion.Euler(0, 90, 0);
            fishKinematic.transform.rotation *= rotate90;


            // DISTANCE MEASURE
            distanceMeasure.transform.position = transform.position;
            distanceMeasure.transform.rotation = flatRotation;


            // DISTANCE BAR
            // must place bar at correct distance from player fish
            Vector3 fishPosition = transform.position;
            float   radians      = degrees * Mathf.Deg2Rad;
            float   distance     = powerBar.GetCurrentPower() * scale;

            float x = fishPosition.x + Mathf.Sin(radians) * distance;
            float y = fishPosition.y;
            float z = fishPosition.z + Mathf.Cos(radians) * distance;

            distanceBar.transform.position = new Vector3(x, y, z);
            distanceBar.transform.rotation = flatRotation;
        }
    }
コード例 #2
0
ファイル: FishMovement.cs プロジェクト: opdev1004/flippyfish
 // Called during a frame when the mouse is released (ie. it was held the previous frame) and the fish is grounded.
 public void ReleaseJump()
 {
     if (canceledClick)      // player wants to cancel current jump so we ignore the current click
     {
         canceledClick = false;
         return;
     }
     else
     {
         PointAtCursor();
         float charge = powerBar.GetCurrentPower();
         // apply small random rotation
         if (charge > 1)
         {
             transform.rotation *= Quaternion.Euler(0, Random.Range(-angleVariance * charge, angleVariance * charge), 0);
         }
         DoJump(charge);
     }
 }