/// <summary> /// Dropping/letting go of a box /// </summary> private void DropBox() { // Tell the box it's been dropped MoveBoxController boxController = pickupObject.GetComponent <MoveBoxController>(); boxController.bePicked = false; boxController.playerHolding = null; audioManager.StopMoveBox(); // Let the player rotate again inputCont.allowRotate = true; // Different reactions for grandma vs baby if (playerId == 0) { inputCont.slowed = false; } else if (playerId == 1) { rb.mass = origWeight; inputCont.canMove = true; } // Turn back on physics for the box pickupObject.gameObject.layer = 0; pickupObject.GetComponent <Rigidbody>().isKinematic = false; pickupObject.GetComponent <Rigidbody>().detectCollisions = true; pickupObject.transform.parent = null; pickupObject.transform.GetChild(0).gameObject.SetActive(true); // Turn off the fake simulated box collider inputCont.fakeBox.SetActive(false); inputCont.haveBox = false; }
/// <summary> /// Is the player currently on the ground? /// </summary> /// <returns>True or false depending on if player is grounded</returns> private bool IsGrounded() { RaycastHit hit; if (haveBox) { MoveBoxController mbCont = pickupObject.GetComponent <MoveBoxController>(); if (playerId == 0 && pickupObject.GetComponent <MoveBoxController>().IsGroundedSmall()) { return(true); } else if (playerId == 1 && pickupObject.GetComponent <MoveBoxController>().IsGrounded()) { return(true); } } return(Physics.SphereCast(transform.position, transform.localScale.x / 1.5f, Vector3.down, out hit, ground)); }
/// <summary> /// Picking up/grabbing a box /// </summary> private void PickUpBox() { // When pick up button is pressed, check if there is a box in reach Collider[] hitColliders = Physics.OverlapBox(pickupPosition.transform.position, transform.localScale / 2); foreach (Collider c in hitColliders) { // Check if it's a box if (c.gameObject.tag == "Grabbable") { pickupObject = c.gameObject; inputCont.pickupObject = pickupObject; MoveBoxController boxController = pickupObject.GetComponent <MoveBoxController>(); // Only pick up a box not grabbed yet if (!boxController.bePicked) { boxController.bePicked = true; boxController.playerHolding = inputCont; inputCont.haveBox = true; // Rotate player towards box, just want y rotation inputCont.allowRotate = false; float itemRotationY = pickupObject.transform.eulerAngles.y % 90; float change = 0; if (itemRotationY > 45) { // items rotated more than 45 add 90 degrees to much change = -90f; } Vector3 relativePos = pickupObject.transform.position - transform.position; relativePos.y = 0; Quaternion rotation = Quaternion.LookRotation(relativePos, Vector3.up); float yRot = Mathf.Round(rotation.eulerAngles.y / 90.0f) * 90.0f + itemRotationY + change; transform.rotation = Quaternion.Euler(new Vector3(0, yRot, 0)); // Different reactions for grandma vs baby if (playerId == 0) { // Grandma can pick up box and move it inputCont.slowed = true; } else if (playerId == 1) { // Baby cat can only grab the box rb.mass = origWeight + 10f; rb.velocity = Vector3.zero; pickupObject.GetComponent <Rigidbody>().velocity = Vector3.zero; inputCont.canMove = false; } pickupObject.gameObject.layer = 13; //change layer so rope doesnt interfer with box // Turn off physics for this box pickupObject.GetComponent <Rigidbody>().isKinematic = true; pickupObject.transform.gameObject.GetComponent <Rigidbody>().detectCollisions = false; pickupObject.transform.parent = transform; pickupObject.transform.GetChild(0).gameObject.SetActive(false); // Turn on a fake collider to simulate the box's collider inputCont.fakeBox.SetActive(true); Vector3 add = new Vector3(0, 0.1f, 0); inputCont.fakeBox.GetComponent <BoxCollider>().center = pickupObject.transform.localPosition + add; inputCont.fakeBox.GetComponent <BoxCollider>().size = pickupObject.transform.localScale; // Only pick up one box at a time break; } } } }