Beispiel #1
0
    private void FollowFish()
    {
        if (!Camera.main.GetComponent <FollowTheBoid>().enabled)
        {
            if (Input.GetKeyDown(KeyCode.F))
            {
                FollowTheFish followFish = Camera.main.GetComponent <FollowTheFish>();

                if (!followFish.enabled)
                {
                    RaycastHit hit;
                    Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                    if (Physics.Raycast(ray, out hit))
                    {
                        Transform objectHit = hit.transform;

                        if (hit.transform != controller.transform)
                        {
                            followFish.Fish   = objectHit;
                            followFish.Offset = new Vector3(0, 0, -100);

                            followFish.enabled = true;
                        }
                    }
                }
                else
                {
                    followFish.enabled = false;
                }
            }
        }
    }
Beispiel #2
0
    /// <summary>
    /// Gets input for the camera and applies the offsets for the main camera.
    /// </summary>
    private void GetCameraPositionChange()
    {
        if (!Camera.main.GetComponent <FollowTheBoid>().enabled)
        {
            Vector3       moveCamera = Vector3.zero;
            FollowTheFish followFish = Camera.main.GetComponent <FollowTheFish>();

            float scroll = Input.GetAxis("Mouse ScrollWheel");

            scroll = scroll == 0 && Input.GetKey(KeyCode.KeypadPlus) ? 0.05f * controller.Scale / 10 : scroll;
            scroll = scroll == 0 && Input.GetKey(KeyCode.KeypadMinus) ? -0.05f * controller.Scale / 10 : scroll;

            if (scroll != 0)
            {
                moveCamera += new Vector3(0, 0, scroll * SCROLLSTEP);
            }

            moveCamera += GetCameraMovement();

            if (followFish.enabled)
            {
                followFish.Offset += moveCamera;

                //var rot = GetCameraRotation();
                //var fish = followFish.Fish;
                //var off = followFish.Offset;


                //followFish.RotationOffset += (fish.right + off) * rot.x;
                //followFish.RotationOffset += (fish.up + off) * rot.y;
                //followFish.RotationOffset += (fish.forward + off) * rot.z;
            }
            else
            {
                //Camera.main.transform.position +=  moveCamera;
                Camera.main.transform.position    += Camera.main.transform.right * moveCamera.x;
                Camera.main.transform.position    += Camera.main.transform.up * moveCamera.y;
                Camera.main.transform.position    += Camera.main.transform.forward * moveCamera.z;
                Camera.main.transform.eulerAngles += GetCameraRotation();
            }
        }
    }