コード例 #1
0
 /// <summary>
 /// Triggered once when hook hits & swing is permitted. Sets initial direction, so we can compare it with the previous direction, to reset acceleration.
 /// </summary>
 protected void CollisionTriggered()
 {
     previousState    = _movement.CurrentState;
     distanceToTarget = Vector2.Distance(target.transform.position, gameObject.transform.position);
     truePhysics      = distanceToTarget < _controller.Height() * 3 ? false : true;
     _controller.GravityActive(false);
     _characterHorizontalMovement.AbilityPermitted = false;
     _movement.ChangeState(CharacterStates.MovementStates.Swinging);
     attached = true;
 }
コード例 #2
0
 /// <summary>
 /// On update we go through all our particle systems and activate them if needed
 /// </summary>
 public override void ProcessAbility()
 {
     base.ProcessAbility();
     HandleParticleSystem(IdleParticles, CharacterStates.MovementStates.Idle);
     HandleParticleSystem(WalkingParticles, CharacterStates.MovementStates.Walking);
     HandleParticleSystem(CrouchingParticles, CharacterStates.MovementStates.Crouching);
     HandleParticleSystem(CrawlingParticles, CharacterStates.MovementStates.Crawling);
     HandleParticleSystem(DanglingParticles, CharacterStates.MovementStates.Dangling);
     HandleParticleSystem(DashingParticles, CharacterStates.MovementStates.Dashing);
     HandleParticleSystem(DivingParticles, CharacterStates.MovementStates.Diving);
     HandleParticleSystem(GrippingParticles, CharacterStates.MovementStates.Gripping);
     HandleParticleSystem(JetpackingParticles, CharacterStates.MovementStates.Jetpacking);
     HandleParticleSystem(JumpingParticles, CharacterStates.MovementStates.Jumping);
     HandleParticleSystem(LadderParticles, CharacterStates.MovementStates.LadderClimbing);
     HandleParticleSystem(LookupParticles, CharacterStates.MovementStates.LookingUp);
     HandleParticleSystem(PushParticles, CharacterStates.MovementStates.Pushing);
     HandleParticleSystem(RunParticles, CharacterStates.MovementStates.Running);
     HandleParticleSystem(WallclingingParticles, CharacterStates.MovementStates.WallClinging);
     HandleParticleSystem(WalljumpParticles, CharacterStates.MovementStates.WallJumping);
     _stateLastFrame = _movement.CurrentState;
 }
コード例 #3
0
 /// <summary>
 /// Checks if the specified state is active, and if yes, triggers the particle system's emission
 /// </summary>
 /// <param name="system">System.</param>
 /// <param name="state">State.</param>
 protected virtual void HandleParticleSystem(ParticleSystem system, CharacterStates.MovementStates state)
 {
     if (system == null)
     {
         return;
     }
     if (_movement.CurrentState == state)
     {
         if (!system.main.loop && _stateLastFrame != state)
         {
             system.Clear();
             system.Play();
         }
         _emissionModule         = system.emission;
         _emissionModule.enabled = true;
     }
     else
     {
         _emissionModule         = system.emission;
         _emissionModule.enabled = false;
     }
 }
コード例 #4
0
ファイル: CharacterWallClinging.cs プロジェクト: andres-03/01
        /// <summary>
        /// If the character is currently wallclinging, checks if we should exit the state
        /// </summary>
        protected virtual void ExitWallClinging()
        {
            if (_movement.CurrentState == CharacterStates.MovementStates.WallClinging)
            {
                // we prepare a boolean to store our exit condition value
                bool shouldExit = false;
                if ((_controller.State.IsGrounded) ||              // if the character is grounded
                    (_controller.Speed.y >= 0))                         // or if it's moving up
                {
                    // then we should exit
                    shouldExit = true;
                }

                // we then cast a ray to the direction's the character is facing, in a down diagonal.
                // we could use the controller's IsCollidingLeft/Right for that, but this technique
                // compensates for walls that have small holes or are not perfectly flat
                Vector3 raycastOrigin = transform.position;
                Vector3 raycastDirection;
                if (_character.IsFacingRight)
                {
                    raycastOrigin    = raycastOrigin + transform.right * _controller.Width() / 2 + transform.up * RaycastVerticalOffset;
                    raycastDirection = transform.right - transform.up;
                }
                else
                {
                    raycastOrigin    = raycastOrigin - transform.right * _controller.Width() / 2 + transform.up * RaycastVerticalOffset;
                    raycastDirection = -transform.right - transform.up;
                }

                // we check if the ray hit anything. If it didn't, or if we're not moving in the direction of the wall, we exit
                if (!InputIndependent)
                {
                    // we cast our ray
                    RaycastHit2D hit = MMDebug.RayCast(raycastOrigin, raycastDirection, WallClingingTolerance, _controller.PlatformMask | _controller.OneWayPlatformMask | _controller.MovingOneWayPlatformMask, Color.black, _controller.Parameters.DrawRaycastsGizmos);

                    if (_character.IsFacingRight)
                    {
                        if ((!hit) || (_horizontalInput <= _inputManager.Threshold.x))
                        {
                            shouldExit = true;
                        }
                    }
                    else
                    {
                        if ((!hit) || (_horizontalInput >= -_inputManager.Threshold.x))
                        {
                            shouldExit = true;
                        }
                    }
                }
                else
                {
                    if (_raycast.collider == null)
                    {
                        shouldExit = true;
                    }
                }

                if (shouldExit)
                {
                    ProcessExit();
                }
            }

            if ((_stateLastFrame == CharacterStates.MovementStates.WallClinging) &&
                (_movement.CurrentState != CharacterStates.MovementStates.WallClinging) &&
                _startFeedbackIsPlaying)
            {
                // we play our exit feedbacks
                StopStartFeedbacks();
                PlayAbilityStopFeedbacks();
            }

            _stateLastFrame = _movement.CurrentState;
        }
コード例 #5
0
ファイル: Character.cs プロジェクト: hlgott1593/LudumDare48
 public void ChangeMovementState(CharacterStates.MovementStates newState)
 {
     MovementState = newState;
     UpdateAnimator();
 }