private void DoGrab(SteamVR_Action_Boolean fromAction, SteamVR_Input_Sources fromSource, bool newState) { //if (doGrabAction.trackedDeviceIndex != parentHand.GetDeviceIndex()) return; if (blaster.IsPrimaryFireModeBlockingGrapple()) { ReleaseGrip(); } if (newState) { DrawGrappleLightning(); } else { ReleaseGrip(); } if (fromAction.stateDown) { if (grabPoint == null) { InstantiateNewGrappleProjectile(); } isGrappleProjectileDeployed = true; // Reset position/momentum grabPoint.transform.position = blaster.spawnTransform.position; grabPoint.velocity = Vector3.zero; grabPoint.gameObject.SetActive(true); grabPoint.AddRelativeForce(blasterMesh.transform.forward * grappleProjectileVelocity, ForceMode.Impulse); } if (newState) { if (isGrappling) { GrappleTo(blaster.spawnTransform.position, grabPoint.position); } else if (isForceGrabbing) { // If the target dissapeared on us, let go if (forceGrabbableTarget == null) { ReleaseGrip(); } else { DoForceGrabDistance(); } } } }
// -------------------------------------------------------------------------------- // New Grapple // -------------------------------------------------------------------------------- // TODO: Apply motion += grapplePoint.velocity? private void DoGrab(SteamVR_Action_Boolean fromAction, SteamVR_Input_Sources fromSource, bool newState) { // TODO: This is causing the player to freeze in place if they activate DoGrab() with their off hand //if (doGrabAction.trackedDeviceIndex != parentHand.GetDeviceIndex()) return; if (blaster.IsPrimaryFireModeBlockingGrapple()) { ReleaseGrip(); } // If the player lets go of the grab button if (!newState) { //audioSource.Stop(); // If we have vertical momentum on the way up, give ourselves a little extra boost if (fromAction.stateUp && motion.y > 0 && currentGrapplePoint != null) { if (currentGrapplePoint.hasCollided) { Debug.Log("Added boost"); } motion.y += addedVerticalMomentum; } ReleaseGrip(); smoothLocomotion.enabled = true; return; } // If this is the first time that we've pressed the grab button if (fromAction.stateDown) { // If we haven't connected with anything yet, fire a projectile if (forceGrabbableTarget == null) { DestroyCurrentGrapplePoint(); currentForceGrabProjectile = blaster.FireNewProjectile(forceGrabProjectilePrefab, forceGrabProjectileVelocity); currentGrapplePoint = currentForceGrabProjectile.GetComponent <GrapplePoint>(); currentGrapplePoint.parentGrappler = this; } } // When the grapple point collided with the target... if (newState && currentForceGrabProjectile != null) { //audioSource.Play(); //audioSource.loop = true; if (currentGrapplePoint.hasCollided) { if (forceGrabbableTarget != null) { // -- This is a force-grabbable object, then pick it up DoForceGrabDistance(); // Not sure why this is needed, but smooth locomotion gets disabled without it. smoothLocomotion.enabled = true; } else { // -- If we've collided with a wall, then grapple to it. smoothLocomotion.activeGrappler = this; smoothLocomotion.enabled = false; GrappleTo(blaster.spawnTransform.position, currentForceGrabProjectile.transform.position); } } } else { smoothLocomotion.enabled = true; } }