Exemplo n.º 1
0
 public void Land()
 {
     audioSourceMultichannel.GetChannel().PlayOneShot(landingClip);
     if (stompCloud != null)
     {
         stompCloud.Emit(10);
     }
     Landed?.Invoke();
 }
Exemplo n.º 2
0
        void Update()
        {
            this.AddGravity();
            this.UnderWaterProccess();

            var oldIsGrouded = this.characterController.isGrounded;

            this.characterController.move(this.velocity);

            var isGrounded = this.characterController.isGrounded;

            if (!oldIsGrouded && isGrounded)
            {
                this.velocityByGravity.x = 0.0f;
            }

            if (!isGrounded && this.velocity.y < 0.0f)
            {
                this.brokableObject?.Broker.Publish(Fall.Get());
            }

            if (this.canPublishLanded)
            {
                if (isGrounded)
                {
                    this.brokableObject?.Broker.Publish(Landed.Get());
                    this.canPublishLanded = false;
                }
            }
            else
            {
                if (!isGrounded)
                {
                    this.canPublishLanded = true;
                }
            }

            if (isGrounded)
            {
                this.velocityByGravity.y = 0.0f;
            }
            if (this.characterController.collisionState.above)
            {
                this.velocityByGravity.y = 0.0f;
            }

            if (this.velocity.x == 0.0f)
            {
                this.brokableObject?.Broker.Publish(Idle.Get());
            }
            else
            {
                this.brokableObject?.Broker.Publish(Move.Get(this.velocity));
            }
            this.velocity = Vector2.zero;
        }
 private void CheckIfLanded()
 {
     if (_allowJump == false && _isGrounded)
     {
         Landed?.Invoke();
         Debug.Log("Landed");
         _isMoving = true;
     }
     _allowJump = true;
 }
Exemplo n.º 4
0
 private void Land()
 {
     CurrentNumOfJumps = 0;
     jumpStarted       = false;
     isFreeFalling     = false;
     animator.SetTrigger("Landed");
     Landed?.Invoke(this, EventArgs.Empty);
     OnLandEvent.Invoke();
     AudioPlayer.PlayEffect(AudioEffects.Sounds.land);
 }
Exemplo n.º 5
0
 private void OnGroundDetected()
 {
     _vertSpeed = 0;
     if (_isGrounded == false)
     {
         Landed?.Invoke();
         //Debug.Log("Landed");
     }
     _isGrounded  = true;
     _justJumped  = false;
     _superJumped = false;
 }
Exemplo n.º 6
0
 private void DoCollision(Collision other, bool wasEnter)
 {
     for (int i = 0;
          i < other.contactCount;
          i++)
     {
         Vector3 normal = other.GetContact(i).normal;
         if (normal.y >= minCosToGround)
         {
             if (wasEnter && !isGrounded)
             {
                 Landed?.Invoke();
             }
             isGrounded     = true;
             contactNormal  = normal;
             groundBody     = other.rigidbody;
             moonJumpGround = other.collider.CompareTag("MoonJump");
         }
     }
 }
Exemplo n.º 7
0
        protected void Update()
        {
            UpdateGround();
            UpdatePlatform();

            if (isClient && !isOwner)
            {
                UpdateRemote();
                return;
            }

            character.view.localRotation = Quaternion.AngleAxis(viewPitch, Vector3.left);
            transform.localRotation      = Quaternion.AngleAxis(yaw, Vector3.up);

            var actualMovement = moveInput.normalized;

            if (IsOnLadder)
            {
                var f = actualMovement.z;
                actualMovement.z = 0;
                y = f * 2;
            }


            // Apply modifiers
            var runSpeed = IsSneaking ? settings.SneakSpeed : settings.runSpeed;

            actualMovement *= runSpeed;

            if (actualMovement.z <= 0)
            {
                actualMovement.z *= settings.backwardSpeedModifier;
            }
            actualMovement.x *= settings.sideSpeedModifier;

            float speedBuff = 1;

            character.Stats.ModifyStat(CharacterStat.MovementSpeed, ref speedBuff);
            actualMovement *= speedBuff;

            if (settings.GainMomentum)
            {
                if (IsGrounded)
                {
                    Momentum = Mathf.Min(Momentum + Time.deltaTime * 0.15f, 1);
                }
                if (actualMovement.z < -0.1f || !IsMoving)
                {
                    Momentum = 0;
                }

                var angle = Vector2.Angle(new Vector2(characterController.velocity.x, characterController.velocity.z).normalized,
                                          new Vector2(lastVelocity.x, lastVelocity.z).normalized);
                Momentum *= 1 - Mathf.Clamp01(angle / 180);

                actualMovement.z *= (1 + Momentum * settings.Momentum);
            }
            lastVelocity = characterController.velocity;

            actualMovement.y = 0;

            var modifier = IsGrounded ? settings.groundControl : settings.airControl;

            actualMovement = Vector3.Lerp(lastMovement, actualMovement, modifier);

            lastMovement = actualMovement;

            // Landing
            if (IsGrounded)
            {
                if (lastGroundedTime < Time.time - 2)
                {
                    DeathByLanding?.Invoke();
                }

                if (lastGroundedTime < Time.time - 0.2f)
                {
                    Momentum *= 0.8f;
                    Landed?.Invoke();
                }
            }

            // Last grounded
            if (IsGrounded || IsOnLadder || InProceduralMovement)
            {
                lastGroundedTime = Time.time;
            }

            // Gravity
            if (settings.useGravity && !IsOnLadder)
            {
                y = Mathf.MoveTowards(y, Physics.gravity.y, Time.deltaTime * 20);
            }

            // Jump
            var wasRecentlyGrounded = lastGroundedTime >= Time.time - settings.JumpGroundedGraceTime;
            var beginJump           = jump && Time.time >= nextJumpTime && wasRecentlyGrounded;

            if (beginJump)
            {
                nextJumpTime = Time.time + settings.JumpCooldown;
                y            = settings.JumpForce;
                Jumped?.Invoke();
            }

            // Move
            characterController.Move(transform.rotation * actualMovement * Time.deltaTime + Vector3.up * y * Time.deltaTime);

            // Consume input
            moveInput = Vector3.zero;
            jump      = false;

            if (isClient && Time.time >= nextSendTime)
            {
                nextSendTime = Time.time + minSendDelay;
                RpcServerMove(transform.position, yaw, viewPitch);
            }
        }