예제 #1
0
        public override void FixedUpdate()
        {
            if (!isLocalPlayer)
            {
                return;
            }

            base.FixedUpdate();

            // Movement
            Vector3 movement = new Vector3(SimpleInput.GetKeyCodeAxis(Game.instance.controls.moveLeft, Game.instance.controls.moveRight), 0, SimpleInput.GetKeyCodeAxis(Game.instance.controls.moveDown, Game.instance.controls.moveUp));

            movement   = Camera.main.transform.TransformDirection(movement);
            movement.y = 0;
            movement.Normalize();

            if (hurtTime > 0)
            {
                hurtTime -= Time.deltaTime;
            }

            if (controller.isGrounded)
            {
                if (canMove)
                {
                    if (movement.z > 0)
                    {
                        direction = Direction.Up;
                    }
                    if (movement.z < 0)
                    {
                        direction = Direction.Down;
                    }
                    if (movement.x < 0)
                    {
                        direction = Direction.Left;
                    }
                    if (movement.x > 0)
                    {
                        direction = Direction.Right;
                    }

                    if (movement != Vector3.zero)
                    {
                        state     = State.Move;
                        movement *= 4f;
                    }
                    else
                    {
                        state = State.Idle;
                    }

                    if (hurtTime <= Time.deltaTime && !justJumped)
                    {
                        if (Input.GetKey(Game.instance.controls.jump))
                        {
                            justJumped   = true;
                            jumpVelocity = 0.25f;
                        }
                    }
                }

                if (!justJumped)
                {
                    jumpVelocity = 0f;
                }

                oldMovement = movement;
            }
            else
            {
                if (controller.velocity.y > 0)
                {
                    state = State.Jump;
                }
                else
                {
                    state      = State.Fall;
                    justJumped = false;
                }

                if (hurtTime > Time.deltaTime)
                {
                    oldMovement = Vector3.zero;
                }

                jumpVelocity -= 0.008f;
            }

            controller.Move(((controller.isGrounded ? (canMove ? movement : Vector3.zero) : oldMovement) + Physics.gravity) * Time.deltaTime + new Vector3(0, jumpVelocity, 0));

            animator.SetFloat("Attack Speed", inventory.slots[currentSlot].item != null ? inventory.slots[currentSlot].item.swingSpeed : Item.fist.swingSpeed);

            // Mouse
            Ray mouseRay = Camera.main.ScreenPointToRay(Input.mousePosition);

            Physics.Raycast(mouseRay, out Game.mouseHit, 100, ~(ignoreLayers | 1 << LayerMask.NameToLayer("Hidden")));
        }