예제 #1
0
    void CheckInput()
    {
        if (player.playerState == Common.PlayerState.Jugando)
        {
            float x = 0;
            float z = 0;

            if (touchControl && player.playerId == Common.PlayerId.TouchPlayer)
            {
                x = touchControl.GetAxis(TouchControl.AxisName.LeftStick_Horizontal);
                z = touchControl.GetAxis(TouchControl.AxisName.LeftStick_Vertical);
            }
            //Movimiento
            else
            {
                x = Input.GetAxis(InputXAxis);
                z = Input.GetAxis(InputYAxis);
            }

            if (Mathf.Abs(x) > DeadZone || Mathf.Abs(z) > DeadZone)
            {
                Vector3 posicion = new Vector3(x, 0, z);

                camRelativeForward = Vector3.Scale(camTransform.forward
                                                   , new Vector3(1, 0, 1)).normalized;

                posicion = posicion.x * camTransform.right
                           - posicion.z * camRelativeForward;

                if (posicion.magnitude > 1.0f)
                {
                    posicion.Normalize();
                }

                moveInput = posicion.magnitude;
                posicion  = Vector3.ProjectOnPlane(posicion, Vector3.up);
                PlayerMove(posicion);


                //Rotación
                Vector3 tpoint = transform.position + posicion;
                if (DebugMovePlayer)
                {
                    Debug.DrawLine(transform.position, tpoint, Color.red);
                }

                Vector3 rotateDirection = tpoint - transform.position;
                float   singleStep      = rotateSpeed * Time.deltaTime;
                Vector3 newDirection    = Vector3.RotateTowards(transform.forward,
                                                                rotateDirection
                                                                , singleStep, 0.0f);

                transform.rotation = Quaternion.LookRotation(newDirection);
            }
            else
            {
                moveInput = 0;
            }
        }
    }