private IEnumerator DisableCollider(Grabable grabable) { yield return(new WaitForSecondsRealtime(2f)); grabable.GetComponent <BoxCollider>().enabled = false; grabable.GetComponent <Rigidbody>().isKinematic = true; }
public void PickUp(Grabable grabable) { _carryingObject = grabable; //F**k off gravity grabable.GetComponent <Rigidbody>().isKinematic = true; grabable.GetComponent <BoxCollider>().enabled = false; grabable.gameObject.transform.SetParent(_grabableHook, false); grabable.gameObject.transform.position = _grabableHook.position; EventManager.Instance.GrabableSpawned(_carryingObject); }
public override bool OnUse(PhysicsProp prop) { if (!IsOwner) { return(false); } Grabable grabable = prop as Grabable; if (grabbed == null && grabbing == null) { Collider grabable_collider = grabable.GetComponent <Collider>(); float grabable_height = grabable_collider.bounds.size.y; grabbing = grabable; if (IsServer) { bool success = grabable.Pickup( grabber: context.gameObject, grab_offset: Vector3.up * (0.2f + (player.cc.height / 2f) + (grabable_height / 2f))); PickupCallback(success); } else { grabable.PickupOnServer( grabber_netId: networkId, grabber_moId: moving_player.GetMovingObjectIndex(), grab_offset: Vector3.up * (0.2f + (player.cc.height / 2f) + (grabable_height / 2f))); grab_timeout_coroutine = utils.WaitAndRun( seconds: grab_timeout, action: () => { grabbing = null; }); } } return(false); }
public Grabable Drop() { //Make sure gravity applies to this object _carryingObject.GetComponent <Rigidbody>().isKinematic = false; _carryingObject.GetComponent <BoxCollider>().enabled = true; //unparent object _carryingObject.transform.SetParent(null); var oldObject = _carryingObject; if (_carryingObject.UsableAction is KoalaAction k) { k.Sit(); } if (_carryingObject.Type == InteractableEnum.EmptyWaterBucket || _carryingObject.Type == InteractableEnum.FullWaterBucket || _carryingObject.Type == InteractableEnum.Sapling) { _carryingObject.gameObject.transform.rotation = new Quaternion(0, 0, 0, 0); } EventManager.Instance.GrabableSpawned(oldObject); _carryingObject = _hands; return(oldObject); }
private void Update() { HandleMovement(); m_PointedItem?.Highlight(false); m_PointedItem = null; Ray ray = new Ray(m_CameraTransform.position, m_CameraTransform.forward); RaycastHit hit; if (Physics.Raycast(ray, out hit, m_GrabDistance, m_GrabableMask)) { m_PointedItem = hit.collider.GetComponentInParent <Grabable>(); if (m_PointedItem) { m_PointedItem.Highlight(true); } } if (Input.GetMouseButtonDown(0) && m_GrabbedItem) { var gun = m_GrabbedItem.GetComponent <Gun>(); if (gun) { gun.Fire(); } } if (Input.GetMouseButtonDown(0) && m_PointedItem) { m_GrabbedItem = m_PointedItem; m_GrabbedItem.Highlight(false); m_GrabbedItem.Grab(m_GrabHook); } if (Input.GetMouseButtonDown(1) && m_GrabbedItem) { m_GrabbedItem.Release(); m_GrabbedItem = null; } if (Input.GetKeyDown(KeyCode.E) && hit.collider) { //Debug.Log(hit.collider.gameObject.name); var button = hit.collider.GetComponentInParent <BigButton>(); if (button) { button.Push(); } } }
void Drop() { if (grabbed != null) { grabbed.transform.parent = null; constructor.Mass -= grabbed.Mass; grabbed.Drop(); Rigidbody2D rigidBody = grabbed.GetComponent <Rigidbody2D>(); if (rigidBody != null) { int multiplier = inputMananger.IsRight ? 1 : -1; rigidBody.AddForce(new Vector2(multiplier * 1, 2) * throwForce); } grabbed = null; } }
void pickup() { if (Input.GetKeyDown(KeyCode.E)) { int x = Screen.width / 2; int y = Screen.height / 2; Ray ray = mainCamera.GetComponent <Camera>().ScreenPointToRay(new Vector3(x, y)); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { Grabable p = hit.collider.GetComponent <Grabable>(); if (p != null) { carrying = true; carriedObject = p.gameObject; p.GetComponent <Rigidbody>().isKinematic = true; } } } }