Exemple #1
0
    void FixedUpdate()
    {
        var dt = Time.fixedDeltaTime;

        if (_teleporting)
        {
            _teleporting       = false;
            _movement.Position = _teleportPosition;
        }

        PreviousVelocity = Velocity;

        if (!IsKinematic)
        {
            Velocity += _manager.Gravity * dt;
            var damping = _manager.GetDamping(IsGrounded);
            if (damping > 0f)
            {
                Velocity *= Mathf.Exp(-damping * dt);
            }
        }

        OnMoving();

        //_movement.Move((PreviousVelocity + Velocity)*dt/2f);
        _movement.Move(Velocity * dt);
        UpdateGrounded();
        CheckCollisions();
    }
Exemple #2
0
    void Update()
    {
        CalculateVelocity();

        controller.Move(velocity * Time.deltaTime, userInput);

        if (controller.collisions.isAbove || controller.collisions.isBelow)
        {
            // Spikes
            if (controller.collisions.isHazard)
            {
                OnDeath();
            }

            // Slope
            if (controller.collisions.isSliding)
            {
                velocity.y += controller.collisions.slopeNormal.y * -gravity * Time.deltaTime;
            }
            else
            {
                velocity.y = 0;
            }
        }
    }
 void OnGUI()
 {
     GUILayout.BeginArea(controlRect);
     if (GUILayout.RepeatButton("Left", GUILayout.ExpandHeight(true)))
     {
         control.Move(true);
     }
     if (GUILayout.RepeatButton("Jump", GUILayout.ExpandHeight(true)))
     {
         control.Jump(control.jumpForce);
     }
     if (GUILayout.RepeatButton("Right", GUILayout.ExpandHeight(true)))
     {
         control.Move(false);
     }
     GUILayout.EndArea();
 }
Exemple #4
0
    // Update is called once per frame
    void Update()
    {
        if (!gm.paused)
        {
            staminaRechargePerFrame = (staminaMax / secondsToFullStamina) * Time.deltaTime;

            if (Time.time - staminaRechargeTimer > idleStaminaTime && currentStamina < staminaMax)
            {
                RechargeStamina(staminaRechargePerFrame);
                if (currentStamina > staminaMax)
                {
                    currentStamina = staminaMax;
                }
            }
            staminaSlider.value = currentStamina / staminaMax;

            //Debug.Log(controller.collisions.below);
            if (prevBelow == true && controller.collisions.below == false && currentJumpCount == nrOfJumps)
            {
                prevBelow = false;
                currentJumpCount--;
            }
            if (controller.collisions.above && velocity.y > 0)
            {
                velocity.y = 0;
            }
            if (controller.collisions.below && velocity.y < 0)
            {
                velocity.y = 0;
            }
            if (controller.collisions.right && velocity.x > 0)
            {
                velocity.x = 0;
            }
            if (controller.collisions.left && velocity.x < 0)
            {
                velocity.x = 0;
            }

            if (controller.collisions.below)
            {
                currentJumpCount = nrOfJumps;
            }

            if (controller.collisions.below)
            {
                if (Mathf.Abs(velocity.x) < groundDrag)
                {
                    velocity.x = 0;
                }
                else
                {
                    velocity.x -= groundDrag * Mathf.Sign(velocity.x);
                }
            }
            else
            {
                if (Mathf.Abs(velocity.x) < airDrag)
                {
                    velocity.x = 0;
                }
                else
                {
                    velocity.x -= airDrag * Mathf.Sign(velocity.x);
                }
            }
            if (canMove)
            {
                foreach (KeyCode jumpKey in jumpKeys)
                {
                    if (Input.GetKeyDown(jumpKey) && currentJumpCount > 0)
                    {
                        currentJumpCount--;
                        velocity.y = jumpVelocity;
                    }
                }

                Vector2 input = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));

                if (input.x != 0)
                {
                    if (Mathf.Abs(velocity.x) < moveSpeed)
                    {
                        velocity.x = input.x * moveSpeed;
                    }
                    else
                    {
                        if (Mathf.Sign(input.x) != Mathf.Sign(velocity.x))
                        {
                            velocity.x += (input.x * moveSpeed) / 10;
                        }
                    }
                }
            }

            //Animation handling
            ///*
            if (velocity.x > 0)
            {
                anim.SetFloat("Speed", 1);
                srPlayer.flipX = false;
            }


            else if (velocity.x < 0)
            {
                anim.SetFloat("Speed", 1);
                srPlayer.flipX = true;
            }
            else
            {
                anim.SetFloat("Speed", 0);
            }
            anim.SetFloat("VerticalSpeed", velocity.y);
            //*/



            velocity.y += Time.deltaTime * gravity;

            controller.Move(velocity * Time.deltaTime);



            if (controller.collisions.below)
            {
                prevBelow = true;
            }
        }
    }
    private void Update()
    {
        // 플레이어 이동
        // left or a = -1  /  right or d = 1
        float x = Input.GetAxisRaw("Horizontal"); // 4

        // 좌우 이동 방향 제어
        movement2D.Move(x);

        // 방향 전환
        if (x == -1)
        {
            spriteRenderer.flipX = true;
        }
        else if (x == 1)
        {
            spriteRenderer.flipX = false;
        }

        // 공격 애니메이션
        if (Input.GetMouseButtonDown(0))
        {
            animator.SetBool("isAttack", true);
        }
        else if (!Input.GetMouseButtonDown(0))
        {
            animator.SetBool("isAttack", false);
        }

        // 점프 애니메이션
        if (Input.GetKey(KeyCode.Space) && !Input.GetKey(KeyCode.S))
        {
            animator.SetBool("isJump", true);
        }
        else if (Input.GetKeyUp(KeyCode.Space))
        {
            animator.SetBool("isJump", false);
        }

        // 달리기 애니메이션
        if (x != 0)
        {
            animator.SetBool("isRun", true);
        }
        else
        {
            animator.SetBool("isRun", false);
        }

        // 플레이어 점프 (스페이스 키를 누르면 점프!)
        if (Input.GetKeyDown(KeyCode.Space) && !Input.GetKey(KeyCode.S))
        {
            movement2D.Jump();
        }

        // 플레이어 s 점프
        if (Input.GetKey(KeyCode.Space) && Input.GetKey(KeyCode.S))
        {
            movement2D.SJump();
        }

        // 스페이스 키를 누르고 있으면 isLongJump = true
        if (Input.GetKey(KeyCode.Space))
        {
            movement2D.isLongJump = true;
        }
        // 스페이스 키를 떼면 isLongJump = false
        else if (Input.GetKeyUp(KeyCode.Space))
        {
            movement2D.isLongJump = false;
        }

        if (HP == 0)
        {
            tempObj = GameObject.Find("Player");
            if (tempObj != null)
            {
                animator.SetBool("isDie", true);
                Destroy(tempObj, 1.2f);
            }
        }

        nowHpbar.fillAmount = (float)HP / (float)MaxHp;
    }
 private void FixedUpdate()
 {
     movement.Rotate(horizontalInput);
     movement.Move(transform.right);
 }
Exemple #7
0
 public void MoveTo(Vector3 target)
 {
     _mvnt.Move(target);
 }
Exemple #8
0
    void Update()
    {
        CalculateVelocity();

        controller.Move(velocity * Time.deltaTime, userInput);
    }