Exemple #1
0
        // Update is called once per frame
        void Update()
        {
            WalkSlow   = 0.1f;
            isGrounded = Physics.CheckSphere(groundCheck.position, groundDistance, groundMask);
            if (isGrounded && Velocity.y < 0)
            {
                Velocity.y = -1f;
            }
            //Movement
            float horizontal = Input.GetAxisRaw("Vertical");        //controller
            float vertical   = Input.GetAxisRaw("Horizontal");

            float   KBHori      = Input.GetAxisRaw("Keyboard W"); //keyboard
            float   KBVert      = Input.GetAxisRaw("Keyboard A");
            Vector3 KBdirection = new Vector3(KBHori, 0f, KBVert).normalized;
            Vector3 direction   = new Vector3(horizontal, 0f, vertical).normalized;

            yVelocity = Velocity.y;
            if (direction.magnitude >= 0.1f)
            {
                float targetAngle = Mathf.Atan2(direction.z, direction.x) * Mathf.Rad2Deg + cam.eulerAngles.y;
                float Angle       = Mathf.SmoothDampAngle(transform.eulerAngles.y, targetAngle + 270, ref TurnSmoothVelocity, TurnTime);
                transform.rotation = Quaternion.Euler(0f, Angle, 0f);

                Vector3 moveDirection = Quaternion.Euler(0f, targetAngle, 0f) * Vector3.forward;
                Velocity   = moveDirection.normalized * speed;
                Velocity.y = yVelocity;
            }
            if (KBdirection.magnitude >= 0.1f)
            {
                float targetAngle = Mathf.Atan2(KBdirection.z, KBdirection.x) * Mathf.Rad2Deg + cam.eulerAngles.y;
                float Angle       = Mathf.SmoothDampAngle(transform.eulerAngles.y, targetAngle + 270, ref TurnSmoothVelocity, TurnTime);
                transform.rotation = Quaternion.Euler(0f, Angle, 0f);

                Vector3 moveDirection = Quaternion.Euler(0f, targetAngle, 0f) * Vector3.forward;
                Velocity   = moveDirection.normalized * speed;
                Velocity.y = yVelocity;
            }
            if (direction.magnitude == 0 & KBdirection.magnitude == 0)
            {
                Velocity.x = Mathf.SmoothDamp(Velocity.x, 0, ref WalkSlowVolx, WalkSlow);
                Velocity.z = Mathf.SmoothDamp(Velocity.z, 0, ref WalkSlowVolz, WalkSlow);
            }
            Velocity.y += gravity * Time.deltaTime;
            controller.Move(Velocity * Time.deltaTime);

            //Basic controls
            bool A = Input.GetButtonDown("Submit");

            if (A == true)
            {
                Jump();
            }
            float DpadUp = Input.GetAxisRaw("DpadUp");

            if (DpadUp >= 0.1f)
            {
                speed = speed + 1;
            }
            if (DpadUp <= -0.1f)
            {
                speed = speed - 1;
            }

            Cursor.visible = false;
        }
        private void Update()
        {
            if (!_inputLock.CanDoAction())
            {
                return;
            }

            ProcessMovementInput();

            ProcessRotationInput();

            if (Input.GetButtonDown("XBoxY"))
            {
                OnYButtonDown?.Invoke();
            }

            if (Input.GetButtonDown("XBoxX"))
            {
                OnXButtonDown?.Invoke();
            }

            if (Input.GetButtonDown("XBoxB"))
            {
                OnBButtonDown?.Invoke();
            }

            if (Input.GetButtonDown("XBoxA"))
            {
                OnAButtonDown?.Invoke();
            }

            if (Input.GetButtonUp("XBoxY"))
            {
                OnYButtonUp?.Invoke();
            }

            if (Input.GetButtonUp("XBoxX"))
            {
                OnXButtonUp?.Invoke();
            }

            if (Input.GetButtonUp("XBoxB"))
            {
                OnBButtonUp?.Invoke();
            }

            if (Input.GetButtonUp("XBoxA"))
            {
                OnAButtonUp?.Invoke();
            }

            if (Input.GetAxisRaw("XBoxLT") <= 0.1f && _ltPressed)
            {
                _ltPressed = false;
                OnLTButtonUp?.Invoke();
            }

            if (Input.GetAxisRaw("XBoxLT") >= 0.9f && !_ltPressed)
            {
                _ltPressed = true;
                OnLTButtonDown?.Invoke();
            }

            if (Input.GetButtonDown("XBoxRb"))
            {
                OnDashInputDown?.Invoke();
            }

            if (Input.GetButtonDown("XBoxLb"))
            {
                OnCallToArmsInputDown?.Invoke();
            }

            if (Input.GetButtonUp("XBoxLb"))
            {
                OnCallToArmsInputUp?.Invoke();
            }

            // TODO non funge per ora
            if (Input.GetAxisRaw("XBoxLT") >= 0.9f && _ltPressed)
            {
                OnLTButtonHeldDown?.Invoke();

                if (Input.GetButtonDown("XBoxY"))
                {
                    OnLT_YButtonDown?.Invoke();
                }

                if (Input.GetButtonDown("XBoxX"))
                {
                    OnLT_XButtonDown?.Invoke();
                }

                if (Input.GetButtonDown("XBoxB"))
                {
                    OnLT_BButtonDown?.Invoke();
                }

                if (Input.GetButtonDown("XBoxA"))
                {
                    OnLT_AButtonDown?.Invoke();
                }
            }
        }