private void UpdateGrabbableHighlight() { // TODO: NOT WORKING var closest = GetClosestGrabbable(); if (closest != null && (closest.grabbedBy != null || !IsInSight(closest))) { if (previousClosest != null) { previousClosest.onDeselected.Invoke(); previousClosest = null; } return; } if (previousClosest != null) { Debug.Log("Deselected"); previousClosest.onDeselected.Invoke(); previousClosest = null; } if (previousClosest != closest) { Debug.Log("Selected"); closest.onSelected.Invoke(); previousClosest = closest; } }
private void UpdateMoving(Grabbable grabbable) { var grabbablePosition = grabbable.transform.position; var position = transform.position; if (IsMove(grabbable, position)) { MoveGrabbableTo(grabbable, grabbablePosition, position); } else { HandleMovingEnd(grabbable); } }
private void HandleMovingEnd(Grabbable grabbable) { var joint = gameObject.AddComponent <FixedJoint>(); joint.connectedBody = grabbable.Body; joint.breakForce = breakForce; grabbable.Body.isKinematic = false; grabbed.Moving = false; grabbed.Joint = joint; onGrab.Invoke(grabbable); }
private void HandleMovingStart(Grabbable grabbable) { var otherGrabber = grabbable.grabbedBy; if (otherGrabber != null) { otherGrabber.Release(); } grabbable.grabbedBy = this; grabbable.Body.isKinematic = true; grabbed = new GrabbedGrabbable( grabbable: grabbable, moving: true ); if (IsMove(grabbable, transform.position)) { onMove.Invoke(grabbable); } }
public GrabbedGrabbable(Grabbable grabbable, bool moving) { Grabbable = grabbable; Moving = moving; }
private bool IsMove(Grabbable grabbable, Vector3 to) { var from = grabbable.Body.ClosestPointOnBounds(to); return(Vector3.Distance(from, to) > grabbedRadius); }
private void MoveGrabbableTo(Grabbable grabbable, Vector3 from, Vector3 to) { var newPosition = Vector3.MoveTowards(from, to, Time.deltaTime * grabSpeed); grabbable.Body.MovePosition(newPosition); }