Beispiel #1
0
    void FinalSceneMovement()
    {
        float xValue = 0;
        float yValue = 0;
        float zValue = 0;

        OurRigid.useGravity = false;

        camerTarget.TurnOffUse();

        //x
        if ((this.transform.position.x + finalSceneMovement * Time.deltaTime > finalSceneLocation.x) &&
            (this.transform.position.x - finalSceneMovement * Time.deltaTime < finalSceneLocation.x))
        {
            this.transform.position = new UnityEngine.Vector3(finalSceneLocation.x, this.transform.position.y, this.transform.position.z);
        }
        else if (this.transform.position.x < finalSceneLocation.x)
        {
            xValue = finalSceneMovement;
        }
        else
        {
            xValue = -finalSceneMovement;
        }

        //y
        if ((this.transform.position.y + finalSceneMovement * Time.deltaTime > finalSceneLocation.y) &&
            (this.transform.position.y - finalSceneMovement * Time.deltaTime < finalSceneLocation.y))
        {
            this.transform.position = new UnityEngine.Vector3(this.transform.position.x, finalSceneLocation.y, this.transform.position.z);
        }
        else if (this.transform.position.y < finalSceneLocation.y)
        {
            yValue = finalSceneMovement;
        }
        else
        {
            yValue = -finalSceneMovement;
        }

        //z
        if ((this.transform.position.z + finalSceneMovement * Time.deltaTime > finalSceneLocation.z) &&
            (this.transform.position.z - finalSceneMovement * Time.deltaTime < finalSceneLocation.z))
        {
            this.transform.position = new UnityEngine.Vector3(this.transform.position.x, this.transform.position.y, finalSceneLocation.z);
        }
        else if (this.transform.position.z < finalSceneLocation.z)
        {
            zValue = finalSceneMovement;
        }
        else
        {
            zValue = -finalSceneMovement;
        }


        //actually move

        UnityEngine.Vector3 amountToMove = new UnityEngine.Vector3(xValue, yValue, zValue).normalized;

        this.transform.position = new UnityEngine.Vector3(this.transform.position.x + (xValue * finalSceneMovement * Time.deltaTime), this.transform.position.y + (yValue * finalSceneMovement * Time.deltaTime), this.transform.position.z + (zValue * finalSceneMovement * Time.deltaTime));


        gameObject.transform.LookAt(FinalLookat);

        // OurRigid.position += amountToMove.x * transform.forward * finalSceneMovement * Time.deltaTime;
        //  OurRigid.position += amountToMove.y * transform.right * finalSceneMovement * Time.deltaTime;
        //OurRigid.position += amountToMove.y * transform.up * finalSceneMovement * Time.deltaTime;
    }
Beispiel #2
0
 void TurnOffFreeMovement()
 {
     CameraTarget.TurnOffUse();
 }
Beispiel #3
0
    void Update()
    {
        Vector3 newItemLocation = new Vector3(0, 0, 0);

        //move right = turn item.
        if (Input.GetKey(KeyCode.Mouse1))
        {
            if (isGrabbing)
            {
                CameraMouseTarget.TurnOffUse();
                FreezeHoldingObject();
                UnFreezeHoldingObject();
                float mouseX = Input.GetAxis("Mouse X") * Time.deltaTime;
                float mouseY = Input.GetAxis("Mouse Y") * Time.deltaTime;

                UpdateDifferencXYRotationAmounts();

                // normal x
                itemBeingHeld.transform.RotateAround(itemBeingHeld.transform.position, Vector3.up, -(mouseX * SideMouseSensitivity));
                //y
                itemBeingHeld.transform.RotateAround(itemBeingHeld.transform.position, Vector3.left, -(mouseY * YRotationAmount * UpDownMouseSensitivity));
                //z
                itemBeingHeld.transform.RotateAround(itemBeingHeld.transform.position, Vector3.forward, (mouseY * ZRotationAmount * UpDownMouseSensitivity));


                isRotating = true;
            }
        }
        else if (isRotating)
        {
            isRotating = false;
            CameraMouseTarget.TurnOnUse();
        }

        if (Input.GetKeyDown(KeyCode.Mouse0) || Input.GetKeyDown(KeyCode.E))
        {
            shouldInteract = true;
            // Debug.Log("Button Pressed");

            if (isGrabbing)
            {
                //drop item
                isGrabbing = false;
                itemBeingHeld.GetComponent <Rigidbody>().useGravity = true;;
                playerControlsTarget.isMovementDisabled             = false;
                currentScrollDesiredLocationOffset      = 0;
                playerControlsTarget.isMovementDisabled = false;
            }
        }
        else
        {
            shouldInteract = false;
        }

        if (isGrabbing)
        {
            // scrolling
            float scrollDifference = Input.GetAxis("Mouse ScrollWheel");
            if (scrollDifference > 0f)
            {
                currentScrollDesiredLocationOffset += scrollAmount * Time.deltaTime;
                if (currentScrollDesiredLocationOffset > maxScrollDesiredLocationOffset)
                {
                    currentScrollDesiredLocationOffset = maxScrollDesiredLocationOffset;
                }
            }
            else if (scrollDifference < 0f)
            {
                currentScrollDesiredLocationOffset -= scrollAmount * Time.deltaTime;
                if (currentScrollDesiredLocationOffset < minScrollDesiredLocationOffset)
                {
                    currentScrollDesiredLocationOffset = minScrollDesiredLocationOffset;
                }
            }

            setDesiredLocation(new Vector3(0, 0, currentDesiredLocation.z + currentScrollDesiredLocationOffset));

            // x
            if (((itemBeingHeld.transform.position.x <= desiredLocation.transform.position.x + (pullSpeed * Time.deltaTime)) &&
                 (itemBeingHeld.transform.position.x >= desiredLocation.transform.position.x - (pullSpeed * Time.deltaTime))) ||
                itemBeingHeld.transform.position.x == desiredLocation.transform.position.x)
            {
                // just round up
                newItemLocation.x = desiredLocation.transform.position.x;
            }
            else if (itemBeingHeld.transform.position.x > desiredLocation.transform.position.x)
            {
                newItemLocation.x = itemBeingHeld.transform.position.x - pullSpeed * Time.deltaTime;
            }
            else if (itemBeingHeld.transform.position.x < desiredLocation.transform.position.x)
            {
                newItemLocation.x = itemBeingHeld.transform.position.x + pullSpeed * Time.deltaTime;
            }

            //y
            if (((itemBeingHeld.transform.position.y <= desiredLocation.transform.position.y + (pullSpeed * Time.deltaTime)) &&
                 (itemBeingHeld.transform.position.y >= desiredLocation.transform.position.y - (pullSpeed * Time.deltaTime))) ||
                itemBeingHeld.transform.position.y == desiredLocation.transform.position.y)
            {
                // just round up
                newItemLocation.y = desiredLocation.transform.position.y;
            }
            else if (itemBeingHeld.transform.position.y > desiredLocation.transform.position.y)
            {
                newItemLocation.y = itemBeingHeld.transform.position.y - pullSpeed * Time.deltaTime;
            }
            else if (itemBeingHeld.transform.position.y < desiredLocation.transform.position.y)
            {
                newItemLocation.y = itemBeingHeld.transform.position.y + pullSpeed * Time.deltaTime;
            }


            //z
            if (((itemBeingHeld.transform.position.z <= desiredLocation.transform.position.z + (pullSpeed * Time.deltaTime)) &&
                 (itemBeingHeld.transform.position.z >= desiredLocation.transform.position.z - (pullSpeed * Time.deltaTime))) ||
                itemBeingHeld.transform.position.z == desiredLocation.transform.position.z)
            {
                // just round up
                newItemLocation.z = desiredLocation.transform.position.z;
            }
            else if (itemBeingHeld.transform.position.z > desiredLocation.transform.position.z)
            {
                newItemLocation.z = itemBeingHeld.transform.position.z - pullSpeed * Time.deltaTime;
            }
            else if (itemBeingHeld.transform.position.z < desiredLocation.transform.position.z)
            {
                newItemLocation.z = itemBeingHeld.transform.position.z + pullSpeed * Time.deltaTime;
            }

            itemBeingHeld.transform.position = newItemLocation;
        }
    }