Ejemplo n.º 1
0
    void Controls()
    {
        if (canmove)
        {
            CheckInteractions();



            dir.x = Inputs.HorizontalAxis();
            dir.z = Inputs.VerticalAxis();
            rot.y = Inputs.CamHorizontalAxis();
            rot.x = Inputs.CamVerticalAxis();


            dir.x *= movespeed;
            dir.z *= movespeed;
            if (charcont.isGrounded)
            {
                dir  = new Vector3(Inputs.HorizontalAxis(), 0, Inputs.VerticalAxis());
                dir  = transform.TransformDirection(dir);
                dir *= movespeed;
            }

            head.transform.eulerAngles = new Vector3(head.transform.eulerAngles.x + rot.x, head.transform.eulerAngles.y, head.transform.eulerAngles.z);
            if (head.transform.eulerAngles.x > 30f && head.transform.eulerAngles.x < -60f && rot.x > 0)
            {
                head.transform.eulerAngles = new Vector3(30f, head.transform.eulerAngles.y, head.transform.eulerAngles.z);
            }
            if (head.transform.eulerAngles.x < -60f && rot.x < 0)
            {
                head.transform.eulerAngles = new Vector3(-60f, head.transform.eulerAngles.y, head.transform.eulerAngles.z);
            }
            transform.eulerAngles = new Vector3(transform.eulerAngles.x, transform.eulerAngles.y + rot.y, transform.eulerAngles.z);
            dir.y -= grav * Time.deltaTime;
            charcont.Move(dir * Time.deltaTime);
        }
    }