protected void Throw() { Debug.Log("Called"); if (!carryObject || !IsThrowable) { return; } if (Input.Charging) { Charged = true; Debug.Log("Charging"); if (PushForce < MaxForce) { PushForce = PushForce + ((MaxForce - MinForce) / 5) * Time.deltaTime; } } if (Charged && !Input.Charging) { Debug.Log("Throw"); if (IsThrowable) { //Item.transform.parent = null; int ItemID = Item.GetComponent <PhotonView>().ViewID; PV.RPC("ThrowObjectAway", RpcTarget.All, new object[] { ItemID, PushForce, transform.forward }); PushForce = MinForce; Charged = false; PickCon.Player = null; PickCon = null; } } }
// This is to separate the basic movement and special skills //PickUp protected void PickUp() { if (Input.PickUp && Grounded) { Debug.Log("StartToCheck"); RaycastHit hit; Ray directionRay = new Ray(transform.position + transform.up * PickupY, transform.forward); DetectObject = Physics.Raycast(directionRay, out hit, PickupDistance); if (Physics.Raycast(directionRay, out hit, PickupDistance)) { Debug.Log("HasSomethingToPick"); if (hit.collider.tag == "PickAbleObject") { Item = hit.collider.gameObject; PickCon = Item.GetComponent <PickUpController>(); if (!PickCon.IsAttached) { Debug.Log("pickItuP"); PickCon.photonView.RequestOwnership(); PickCon.Player = this; RaycastHit TestUnderbound; Ray downRay = new Ray(Item.transform.position, -Vector3.up); Physics.Raycast(downRay, out TestUnderbound); float LowerBound = TestUnderbound.distance; float RiseDistance = ObjectHolder.transform.localPosition.y; // Use the PunRPC to set the object's position to the position we what int ItemID = Item.GetComponent <PhotonView>().ViewID; int ViewID = PV.ViewID; PV.RPC("RiseTheObject", RpcTarget.All, new object[] { ItemID, ViewID, RiseDistance + LowerBound }); State = PlayerState.Lifting; } } } } }
protected void ThrowObjectAway(int ItemID, float PushForce, Vector3 pushDirection) { Item = PhotonView.Find(ItemID).gameObject; PickUpController PickCon = Item.GetComponent <PickUpController>(); PickCon.photonView.TransferOwnership(PickCon.Photon_View_Id); PickCon.IsAttached = false; Item.transform.parent = null; Physics.IgnoreCollision(Item.GetComponent <Collider>(), MainCollider, false); Rigidbody ItemRB = Item.GetComponent <Rigidbody>(); ItemRB.constraints = RigidbodyConstraints.None; ItemRB.useGravity = true; Item.GetComponent <Rigidbody>().AddForce(pushDirection * PushForce); Item = null; IsThrowable = false; carryObject = false; }
protected void RiseTheObject(int ItemID, int ViewID, float LocalDistanceY) { Item = PhotonView.Find(ItemID).gameObject; PickUpController PickCon = Item.GetComponent <PickUpController>(); Physics.IgnoreCollision(Item.GetComponent <Collider>(), PhotonView.Find(ViewID).gameObject.GetComponent <Collider>(), true); if (carryObject = false && !PickCon.IsAttached) { PickCon.photonView.TransferOwnership(ViewID); } Item.transform.SetParent(transform); Item.gameObject.transform.localPosition = new Vector3(Item.gameObject.transform.localPosition.x, LocalDistanceY, Item.gameObject.transform.localPosition.z); DistanceY = Item.gameObject.transform.localPosition.y; DistanceX = Item.gameObject.transform.localPosition.x; DistanceZ = Item.gameObject.transform.localPosition.z; Rigidbody ItemRB = Item.GetComponent <Rigidbody>(); ItemRB.constraints = RigidbodyConstraints.FreezeRotation; ItemRB.useGravity = false; PickCon.IsAttached = true; carryObject = true; IsThrowable = true; }