Example #1
0
        /// <summary>
        /// Calcutaing Euler physics on y axis
        /// </summary>
        private void VerticalMovement()
        {
            float gravMultiplier = 1;

            //detech ground
            bool wantsToJump   = Input.GetButtonDown("Jump");
            bool isHoldingJump = Input.GetButton("Jump");

            if (wantsToJump && isGrounded)
            {
                velocity.y       = jumpImpulse;
                isJumpingUpWards = true;
                isGrounded       = false;



                SoundEffectBoard.PlayJump(transform.position);
            }

            if (!isHoldingJump || velocity.y < 0)
            {
                isJumpingUpWards = false;
            }
            if (isJumpingUpWards)
            {
                gravMultiplier = .5f;
            }

            //applying force of gravity to velocity
            velocity.y -= gravity * Time.deltaTime * gravMultiplier;


            //clamp vertical speed
            //if (velocity.y < -1) velocity.y = -1;
        }
Example #2
0
 void Start()
 {
     if (main == null)
     {
         main = this;
     }
     else
     {
         Destroy(this.gameObject);
     }
 }