private void FixedUpdate() { if (Vector3.Distance(moveTarget, transform.position) < 0.05f && isMoving) { isMoving = false; rb.velocity = Vector3.zero; PlanTargetPlayer(initialDelay: 0); } if (isMoving) { rb.AddForceTowards(transform.position, moveTarget); } }
// Update is called once per frame void FixedUpdate() { if (SteamVR_Input._default.inActions.GrabGrip.GetState(SteamVR_Input_Sources.Any)) { if (grabPauseTime != 0 && (Time.time - grabPauseTime) < 0.5f) { callingBackSaber = true; } else { grabPauseTime = 0; } grabPressed = true; } else { if (grabPressed == true) { grabPauseTime = Time.time; } grabPressed = false; callingBackSaber = false; } if (callingBackSaber) { if (isSaberActive) { ToggleSaber(); } PauseGravity(duration: 2); Transform sourceTransform = transform; if (interactable != null && interactable.handFollowTransform != null) { sourceTransform = interactable.handFollowTransform; } Hand hand = Player.instance.leftHand; if (!SteamVR_Input._default.inActions.GrabGrip.GetState(SteamVR_Input_Sources.LeftHand)) { hand = Player.instance.rightHand; } rb.AddForceTowards(sourceTransform.position, hand.objectAttachmentPoint.transform.position); } if (!energyLocked) { rb.useGravity = (gravityPausedTime == 0); } }
void MoveLockedObjectTowardsTarget(Vector3 position, Quaternion rotation) { if (lockedRigidbody == null) { return; } var sourceTransform = LockedObjectSourceTransform(); float moveSpeed = baseMoveSpeed / MassMoveDecreaseFactor(); if (!useAdvanceMovePhysics) { //Simple version (in case of inability to use Forcemove sources) Vector3 grabDirection = position - sourceTransform.position; float currentDistance = grabDirection.magnitude; moveSpeed = Mathf.Min(moveSpeed, grabDirection.magnitude); lockedRigidbody.velocity = moveSpeed * grabDirection.normalized; Quaternion fullRotation = sourceTransform.rotation * Quaternion.Inverse(rotation); float rotationSpeed = moveSpeed / 360.0f; lockedRigidbody.angularVelocity = rotationSpeed * fullRotation.eulerAngles; } else { float flightTime = Mathf.Min(maxFlightTime, Mathf.Max(minFlightTime, initialLockedDragDistance / moveSpeed)); // Debug.Log("Flighttime: " + flightTime); float damping = 1.2f; float frequency = 1.0f / flightTime; if (doTranslationMove) { lockedRigidbody.AddForceTowards(sourceTransform.position, position, damping, frequency); } if (doRotationMove) { lockedRigidbody.AddTorqueTowards(sourceTransform.rotation, rotation, damping, frequency); } } }
private void FixedUpdate() { if ((isCollisioning && isGrabbed)) { EnableRealLifeMGhostMesh(); // Try to go back to real life object /* * var delta = realLifeGrabSpotTransform.transform.position - physicsVRGrabSpotTransform.position; * rb.AddForce(delta * forceCatchupScale); * * var deltaRotation = Quaternion.FromToRotation(physicsVRGrabSpotTransform.forward, realLifeGrabSpotTransform.transform.forward); * rb.AddTorque(deltaRotation.eulerAngles* torqueCatchupScale); */ var forceCatchupScale = this.forceCatchupScale; var torqueCatchupScale = this.torqueCatchupScale; if (isJoiningBack) { forceCatchupScale *= 4; torqueCatchupScale *= 4; } rb.AddForceTowards(physicsVRGrabSpotTransform.position, realLifeGrabSpotTransform.position, frequency: forceCatchupScale); rb.AddTorqueTowards(physicsVRGrabSpotTransform.rotation, realLifeGrabSpotTransform.transform.rotation, frequency: torqueCatchupScale); // Small additional force if the hand is in the right position, but bended rb.AddForceTowards(physicsVRCollisionSpotTransform.position, realLifeCollisionSpotTransform.position, frequency: forceCatchupScale / 2); if (isGrabbed) { float distance = Vector3.Distance(physicsVRCollisionSpotTransform.position, realLifeCollisionSpotTransform.position); float amplitude = Mathf.Clamp(distance / maxDistance, 0, 1); OVRInput.SetControllerVibration(frequency: amplitude, amplitude: amplitude, controllerKind); } else { OVRInput.SetControllerVibration(0, 0.1f, controllerKind); } } else if (isJoiningBack) { var returnStart = joiningBackEndTime - joiningBackDuration; var returnProgress = (Time.time - returnStart) / joiningBackDuration; physicsVRObject.transform.position = Vector3.Lerp(physicsVRObject.transform.position, realLifeObject.transform.position, returnProgress); physicsVRObject.transform.rotation = Quaternion.Lerp(physicsVRObject.transform.rotation, realLifeObject.transform.rotation, returnProgress); physicsVRObject.GetComponent <Rigidbody>().velocity = Vector3.zero; physicsVRObject.GetComponent <Rigidbody>().angularVelocity = Vector3.zero; if (isGrabbed) { OVRInput.SetControllerVibration(0, 0, controllerKind); } } else { DisableRealLifeGhostMesh(); physicsVRObject.transform.position = realLifeObject.transform.position; physicsVRObject.transform.rotation = realLifeObject.transform.rotation; if (isGrabbed) { OVRInput.SetControllerVibration(0, 0, controllerKind); } } }
public void PlayHitAnimation(GameObject hitObject) { Rigidbody hand = ChooseHand(hitObject); hand.AddForceTowards(hitObject.transform, 100); }