Touch Camera Look

hello, if anybody can help me I found this touchfield script that works like a charm on a 3rd person camera my request will be if anybody can show me how to make the camera move up and down, currently only move left and right but since i’m working on a RPG game I need all 4 directions for the camera so I can pick up items and aim my bow or magic

here are the scripts…

using System.Collections;
using System.Collections.Generic;
using System.Security.Cryptography;
using UnityEngine;
using UnityStandardAssets.Characters.ThirdPerson;

public class ThirdPersonInput : MonoBehaviour
{
    public FixedJoystick LeftJoystick;
    public FixedButton Button;
    public FixedTouchField Touchfield;

    protected ThirdPersonUserControl Control;
    protected float CameraAngle;
    protected float CameraAngleSpeed = 0.3f;

    // Start is called before the first frame update
    void Start()
    {
        Control = GetComponent<ThirdPersonUserControl>();
    }

    // Update is called once per frame
    void Update()
    {
        Control.m_Jump = Button.Pressed;
        Control.h = LeftJoystick.Direction.x;
        Control.v = LeftJoystick.Direction.y;
        CameraAngle += Touchfield.TouchDist.x * CameraAngleSpeed;
        Camera.main.transform.position = transform.position + Quaternion.AngleAxis(CameraAngle, Vector3.up)* new Vector3(0, 1, -2);
        Camera.main.transform.rotation = Quaternion.LookRotation(transform.position + Vector3.up * 1f - Camera.main.transform.position, Vector3.up);
    }
}

and for the touchfield…

using UnityEngine;
using UnityEngine.EventSystems;
public class FixedTouchField : MonoBehaviour, IPointerDownHandler, IPointerUpHandler
{
    [HideInInspector]
    public Vector2 TouchDist;
    [HideInInspector]
    public Vector2 PointerOld;
    [HideInInspector]
    protected int PointerId;
    [HideInInspector]
    public bool Pressed;
    // Use this for initialization
    void Start()
    {
    }
    // Update is called once per frame
    void Update()
    {
        if (Pressed)
        {
            if (PointerId >= 0 && PointerId < Input.touches.Length)
            {
                TouchDist = Input.touches[PointerId].position - PointerOld;
                PointerOld = Input.touches[PointerId].position;
            }
            else
            {
                TouchDist = new Vector2(Input.mousePosition.x, Input.mousePosition.y) - PointerOld;
                PointerOld = Input.mousePosition;
            }
        }
        else
        {
            TouchDist = new Vector2();
        }
    }
    public void OnPointerDown(PointerEventData eventData)
    {
        Pressed = true;
        PointerId = eventData.pointerId;
        PointerOld = eventData.position;
    }

    public void OnPointerUp(PointerEventData eventData)
    {
        Pressed = false;
    }
}

Please use code tags: Using code tags properly

How to report problems productively in the Unity3D forums:

http://plbm.com/?p=220

1 Like

thank you and sorry
and I don’t have errors or anything I just don’t know how to make it look up and down aside from the left right input ( my priority right now is to launch my project and after i’ll pay for a proper class )

like I said first post everything works fine I just need the camera to also look up and down aside from left and right which are working just fine

Time to start inserting strategic Debug.Log("I am here!"); type calls throughout the code to find out:

  1. is code even running?
  2. what parts are running
  3. what are values at different parts?
    etc

Just basic debugging really.

maybe i’m not explaining right, the code does what it’s supposed to do except the camera only moves left and right I need somebody to complete the code so that the camera will also move up and down , I tried something but all it did was turn the camera upside down lol since I have no idea how the touch field was written I don’t know the logic behind it so I cant modify it myself
in simpler words " mouse aim camera" moves in whichever direction you move your mouse
I want the same movements on the touchfield but in this script the camera only moves left and right so is incomplete like I said in first post I need to be able to pick up things and talk to npc so I need free movements so I can point wherever I need to I cant pick up things from the floor if I cant turn my camera downwards

is fine ill just highlight objects with just left and right movements and open a different ui window to pick up stuff instead of aiming directly on them to pick up, seems nobody cares to help complete a script without being payed first , it kills the purpose of this forum, lock this thread please