Exemplo n.º 1
0
        void reelInGrapple(float triggerValue)
        {
            // Has the collider been destroyed or disabled?
            if (validTargetFound && grappleTargetCollider != null && !grappleTargetCollider.enabled)
            {
                dropGrapple();
                return;
            }

            if (validTargetFound && currentGrappleDistance > MinReelDistance)
            {
                // Move object towards our hand
                if (isDynamic)
                {
                    grappleTargetRigid.isKinematic      = false;
                    grappleTargetRigid.transform.parent = grappleTargetParent;
                    grappleTargetRigid.useGravity       = false;
                    grappleTargetRigid.AddForce((MuzzleTransform.position - grappleTargetRigid.transform.position) * 0.1f, ForceMode.VelocityChange);

                    //r.MovePosition(MuzzleTransform.position * Time.deltaTime);
                }
                // Move character towards Hit location
                else
                {
                    Vector3 moveDirection = (HitTargetPrefab.position - MuzzleTransform.position) * GrappleReelForce;

                    // Turn off gravity before we move
                    changeGravity(false);

                    // Use smooth loco method if available
                    if (smoothLocomotion)
                    {
                        smoothLocomotion.MoveCharacter(moveDirection * Time.deltaTime * triggerValue);
                    }
                    // Fall back to character controller
                    else if (characterController)
                    {
                        characterController.Move(moveDirection * Time.deltaTime * triggerValue);
                    }
                }
            }
            else if (validTargetFound && currentGrappleDistance <= MinReelDistance)
            {
                if (isDynamic)
                {
                    //grappleTargetRigid.useGravity = true;
                    grappleTargetRigid.velocity         = Vector3.zero;
                    grappleTargetRigid.isKinematic      = true;
                    grappleTargetRigid.transform.parent = transform;
                }

                if (!climbing && !isDynamic)
                {
                    // Add climbable / grabber
                    ClimbHelper.transform.localPosition = Vector3.zero;
                    playerClimbing.AddClimber(ClimbHelper, thisGrabber);
                    climbing = true;
                }
            }
        }
Exemplo n.º 2
0
        // Apply Gravity in LateUpdate to ensure it gets applied after any character movement is applied in Update
        void LateUpdate()
        {
            // Apply Gravity to Character Controller
            if (GravityEnabled && characterController != null && characterController.enabled)
            {
                _movementY += Gravity.y * Time.deltaTime;

                // Default to smooth locomotion
                if (smoothLocomotion)
                {
                    smoothLocomotion.MoveCharacter(new Vector3(0, _movementY, 0) * Time.deltaTime);
                }
                // Fallback to character controller
                else if (characterController)
                {
                    characterController.Move(new Vector3(0, _movementY, 0) * Time.deltaTime);
                }

                // Reset Y movement if we are grounded
                if (characterController.isGrounded)
                {
                    _movementY = 0;
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Move the character controller to new camera position
        /// </summary>
        public virtual void CheckCharacterCollisionMove()
        {
            if (!MoveCharacterWithCamera || characterController == null)
            {
                return;
            }

            Vector3 initialCameraRigPosition = CameraRig.transform.position;
            Vector3 cameraPosition           = CenterEyeAnchor.position;
            Vector3 delta = cameraPosition - characterController.transform.position;

            // Ignore Y position
            delta.y = 0;

            // Move Character Controller and Camera Rig to Camera's delta
            if (delta.magnitude > 0.0f)
            {
                if (smoothLocomotion)
                {
                    smoothLocomotion.MoveCharacter(delta);
                }
                else if (characterController)
                {
                    characterController.Move(delta);
                }

                // Move Camera Rig back into position
                CameraRig.transform.position = initialCameraRigPosition;
            }
        }
Exemplo n.º 4
0
        void doJet(float triggerValue)
        {
            moveDirection = transform.forward * JetForce;

            // Use smooth loco method if available
            if (smoothLocomotion)
            {
                if (smoothLocomotion.ControllerType == PlayerControllerType.CharacterController)
                {
                    smoothLocomotion.MoveCharacter(moveDirection * Time.deltaTime * triggerValue);
                }
                else if (smoothLocomotion.ControllerType == PlayerControllerType.Rigidbody)
                {
                    //smoothLocomotion.MoveRigidPlayer(moveDirection * triggerValue);

                    // Handle this in LFixedUpdate
                    // Rigidbody rb = smoothLocomotion.GetComponent<Rigidbody>();

                    // moveDirection += new Vector3(0, smoothLocomotion.RigidBodyGravity, 0);

                    addRigidForce = moveDirection * triggerValue;
                    // rb.AddRelativeForce(moveDirection * triggerValue, fm);

                    // smoothLocomotion.MoveCharacter(moveDirection * Time.deltaTime * triggerValue);
                }
            }
            // Fall back to character controller
            else if (characterController)
            {
                characterController.Move(moveDirection * Time.deltaTime * triggerValue);
            }

            // Gravity is always off while jetting
            ChangeGravity(false);

            // Sound
            if (!audioSource.isPlaying)
            {
                audioSource.pitch = Time.timeScale;
                audioSource.Play();
            }

            // Particle FX
            if (JetFX != null && !JetFX.isPlaying)
            {
                JetFX.Play();
            }

            //Haptics
            if (input && thisGrabber != null)
            {
                input.VibrateController(0.1f, 0.5f, 0.2f, thisGrabber.HandSide);
            }
        }
Exemplo n.º 5
0
        public virtual void CheckMovingPlatform()
        {
            bool onMovingPlatform = false;

            if (groundHit.collider != null && DistanceFromGround < 0.01f)
            {
                CurrentPlatform = groundHit.collider.gameObject.GetComponent <MovingPlatform>();

                if (CurrentPlatform)
                {
                    onMovingPlatform = true;

                    // This is another potential method of moving the character instead of parenting it
                    if (CurrentPlatform.MovementMethod == MovingPlatformMethod.PositionDifference && CurrentPlatform != null && CurrentPlatform.PositionDelta != Vector3.zero)
                    {
                        if (smoothLocomotion)
                        {
                            smoothLocomotion.MoveCharacter(CurrentPlatform.PositionDelta);
                        }
                        else if (characterController)
                        {
                            characterController.Move(CurrentPlatform.PositionDelta);
                        }
                    }

                    // For now we can parent the characterController object to move it along. Rigidbodies may want to change friction materials or alter the player's velocity
                    if (CurrentPlatform.MovementMethod == MovingPlatformMethod.ParentToPlatform && characterController != null)
                    {
                        if (onMovingPlatform)
                        {
                            characterController.transform.parent = groundHit.collider.transform;
                            requiresReparent = true;
                        }
                    }
                }
            }
            else
            {
                // Reset our platform if no longer on one
                if (CurrentPlatform != null)
                {
                    CurrentPlatform = null;
                }
            }

            // Check if we need to reparent the character after hopping off a platform
            if (!onMovingPlatform && wasOnPlatform && requiresReparent)
            {
                characterController.transform.parent = _initialCharacterParent;
            }

            wasOnPlatform = onMovingPlatform;
        }
Exemplo n.º 6
0
        public void CheckPlayerControls()
        {
            // Require focus
            if (RequireGameFocus && Application.isEditor && !Application.isFocused)
            {
                return;
            }

            // Player Up / Down
            if (AllowUpDownControls)
            {
                if (PlayerUpAction != null && PlayerUpAction.action.ReadValue <float>() == 1)
                {
                    player.ElevateCameraHeight = Mathf.Clamp(player.ElevateCameraHeight + Time.deltaTime, 0.2f, 5f);
                }
                else if (PlayerDownAction != null && PlayerDownAction.action.ReadValue <float>() == 1)
                {
                    player.ElevateCameraHeight = Mathf.Clamp(player.ElevateCameraHeight - Time.deltaTime, 0.2f, 5f);
                }
            }

            // Force Forward Arrow
            if (ForceStraightTeleportRotation && playerTeleport != null && playerTeleport.ForceStraightArrow == false)
            {
                playerTeleport.ForceStraightArrow = true;
            }

            // Player Move Forward / Back, Snap Turn
            if (smoothLocomotion != null && smoothLocomotion.enabled == false)
            {
                // Manually allow player movement if the smooth locomotion component is disabled
                smoothLocomotion.CheckControllerReferences();
                smoothLocomotion.UpdateInputs();

                if (smoothLocomotion.ControllerType == PlayerControllerType.CharacterController)
                {
                    smoothLocomotion.MoveCharacter();
                }
                else if (smoothLocomotion.ControllerType == PlayerControllerType.Rigidbody)
                {
                    smoothLocomotion.MoveRigidCharacter();
                }
            }
        }
Exemplo n.º 7
0
        public void CheckPlayerControls()
        {
            // Player Up / Down
            if (Input.GetKey(PlayerUp))
            {
                player.ElevateCameraHeight = Mathf.Clamp(player.ElevateCameraHeight + Time.deltaTime, 0.2f, 5f);
            }
            else if (Input.GetKey(PlayerDown))
            {
                player.ElevateCameraHeight = Mathf.Clamp(player.ElevateCameraHeight - Time.deltaTime, 0.2f, 5f);
            }

            // Player Move Forward / Back, Snap Turn
            if (smoothLocomotion != null && smoothLocomotion.enabled == false)
            {
                // Manually allow player movement if the smooth locomotion component is disabled
                smoothLocomotion.UpdateInputs();
                smoothLocomotion.MoveCharacter();
            }
        }
Exemplo n.º 8
0
        void doJet(float triggerValue)
        {
            Vector3 moveDirection = transform.forward * JetForce;

            // Use smooth loco method if available
            if (smoothLocomotion)
            {
                smoothLocomotion.MoveCharacter(moveDirection * Time.deltaTime * triggerValue);
            }
            // Fall back to character controller
            else if (characterController)
            {
                characterController.Move(moveDirection * Time.deltaTime * triggerValue);
            }

            // Gravity is always off while jetting
            ChangeGravity(false);

            // Sound
            if (!audioSource.isPlaying)
            {
                audioSource.pitch = Time.timeScale;
                audioSource.Play();
            }

            // Particle FX
            if (JetFX != null && !JetFX.isPlaying)
            {
                JetFX.Play();
            }

            //Haptics
            if (input && thisGrabber != null)
            {
                input.VibrateController(0.1f, 0.5f, 0.2f, thisGrabber.HandSide);
            }
        }
Exemplo n.º 9
0
        protected virtual void checkClimbing()
        {
            GrippingClimbable = GrippingAtLeastOneClimbable();

            // Check events
            if (GrippingClimbable && !wasGrippingClimbable)
            {
                onGrabbedClimbable();
            }

            if (wasGrippingClimbable && !GrippingClimbable)
            {
                onReleasedClimbable();
            }

            if (GrippingClimbable)
            {
                moveDirection = Vector3.zero;

                int   count  = 0;
                float length = climbers.Count;
                for (int i = 0; i < length; i++)
                {
                    Grabber climber = climbers[i];
                    if (climber != null && climber.HoldingItem)
                    {
                        // Add hand offsets
                        if (climber.HandSide == ControllerHand.Left)
                        {
                            controllerMoveAmount = previousLeftControllerPosition - LeftControllerTransform.position;
                        }
                        else
                        {
                            controllerMoveAmount = previousRightControllerPosition - RightControllerTransform.position;
                        }

                        // Always use last grabbed hand
                        if (count == length - 1)
                        {
                            moveDirection = controllerMoveAmount;

                            // Check if Climbable object moved position
                            moveDirection -= climber.PreviousPosition - climber.DummyTransform.position;;
                        }

                        count++;
                    }
                }

                // Apply movement to player
                if (smoothLocomotion)
                {
                    if (smoothLocomotion.ControllerType == PlayerControllerType.CharacterController)
                    {
                        smoothLocomotion.MoveCharacter(moveDirection);
                    }
                    else if (smoothLocomotion.ControllerType == PlayerControllerType.Rigidbody)
                    {
                        smoothLocomotion.MoveRigidCharacter(moveDirection);

                        // Rigidbody rigid = smoothLocomotion.GetComponent<Rigidbody>();
                        // rigid.velocity = Vector3.MoveTowards(rigid.velocity, (moveDirection * 5000f) * Time.fixedDeltaTime, 1f);
                    }
                }
                else if (characterController)
                {
                    characterController.Move(moveDirection);
                }
            }

            // Update any climber previous position
            for (int x = 0; x < climbers.Count; x++)
            {
                Grabber climber = climbers[x];
                if (climber != null && climber.HoldingItem)
                {
                    if (climber.DummyTransform != null)
                    {
                        // Use climber position if possible
                        climber.PreviousPosition = climber.DummyTransform.position;
                    }
                    else
                    {
                        climber.PreviousPosition = climber.transform.position;
                    }
                }
            }

            wasGrippingClimbable = GrippingClimbable;
        }