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;
}
}