private void FixedUpdate() { if (objectWasThrow && rb.velocity.magnitude <= 0.01f) { objectWasThrow = false; } if (!CanUpdatePhysicsMovement()) { return; } switch (physicsUpdateState) { case PhysicsUpdateState.InCollision: physicsUpdateState = InCollisionPhysicsUpdateState(); break; case PhysicsUpdateState.NoCollision: physicsUpdateState = NoCollisionPhysicsUpdate(); break; } }
/// <summary> /// Called by VR_Input, to let know what we are grabbing this object /// </summary> /// <param name="controller"></param> public virtual void OnGrabSuccess(VR_Controller controller) { if (preventDefault) { activeController = controller; CurrentGrabState = GrabState.Grab; RaiseOnGrabStateChangeEvent(CurrentGrabState); return; } previusKinematicValue = rb.isKinematic; //stop this object to be interactable CanInteract = false; //set the active controller activeController = controller; if (rb != null && grabMode == GrabMode.Joint) { rb.isKinematic = true; originalInterpolateMode = rb.interpolation; rb.interpolation = RigidbodyInterpolation.None; } if (grabMode == GrabMode.Physics) { physicsUpdateState = PhysicsUpdateState.NoCollision; previusUseGravityState = rb.useGravity; previusGravityState = rb.useGravity; rb.useGravity = false; rb.isKinematic = false; rb.useGravity = false; rb.interpolation = RigidbodyInterpolation.Interpolate; originalInterpolateMode = rb.interpolation; OverridePhysicsMaterial(zeroFrictionOrBouncinessMaterial); activeController.UseRotationOffset = false; activeController.UsePositionOffset = false; } //disable collision with the grabbable and the hand if (activeController.Collider != null) { IgnoreCollision(activeController.Collider); } //if this object shoudl fly to hand disable colliders while flying otherwise set desire collider state if (shouldFly) { //disable colliders while flying ChangeCollidersEnable(false); } else { ChangeCollidersEnable(enableColliderOnGrab); } //if we are using a perfect grab if (perfectGrab) { //parent the objects so they exist on the same space transform.parent = activeController.transform; GrabController.SetVisibility(!GetCurrentHandInteractSettings().hideHandOnGrab); SetupFixedJoint(); //set the current grab state CurrentGrabState = GrabState.Grab; //raise grab state change event RaiseOnGrabStateChangeEvent(CurrentGrabState); return; } else { //set fly values if (shouldFly) { grabStartTime = Time.time; grabStartPosition = transform.position; grabStartRotation = transform.rotation; } else { SetFinalGrabState(); } CurrentGrabState = shouldFly ? GrabState.Flying : GrabState.Grab; } //raise the event RaiseOnGrabStateChangeEvent((shouldFly ? GrabState.Flying : GrabState.Grab)); }