void TurnOnFreeMovement() { CameraTarget.TurnOnUse(); }
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; } }