- Home /
Question by
twotostudio · Oct 26, 2021 at 01:46 PM ·
androidrotationdrag
Drag code issue on mobile
I am using this code to rotate the camera by dragging within certain limits. Everything works great in the editor. However, when I use this code on mobile, the camera starts by turning directly to the point I clicked. And I don't want it to be like that. How can I solve this problem?
public class KameraKod : MonoBehaviour
{
public float speedH = 1.0f;
public float speedV = 1.0f;
float yaw = 0.0f;
float pitch = 0.0f;
public static bool move = false;
private void Start()
{
move = false;
}
void Update()
{
if (HandScript.hangiSilah == 2)
{
if (yaw >= 30.532f)
{
//yaw = 30.532f;
yaw = Mathf.Lerp(yaw, 30.532f, 0.11f);
}
if (yaw <= -29.182f)
{
yaw = Mathf.Lerp(yaw, -29.182f, 0.11f);
}
if (pitch >= 22.77f)
{
pitch = Mathf.Lerp(pitch, 22.77f, 0.11f);
}
if (pitch <= -22f )
{
pitch = Mathf.Lerp(pitch, -22f, 0.11f);
}
if (Input.GetMouseButtonDown(0))
{
move = true;
}
if (Input.GetMouseButtonUp(0))
{
move = false;
}
if (move == true)
{
yaw += speedH * Input.GetAxis("Mouse X");
pitch -= speedV * Input.GetAxis("Mouse Y");
transform.eulerAngles = new Vector3(pitch, yaw, 0.0f);
}
}
}
}
Comment
Answer by twotostudio · Oct 26, 2021 at 05:34 PM
Input.GetAxis("Mouse X") Input.GetAxis("Mouse Y") Is there anyone who can solve the problem that these functions cause on mobile? :(
Answer by DenisIsDenis · Oct 30, 2021 at 03:04 AM
Maybe you need to process this data: Input.GetTouch(0).deltaPosition.x
and Input.GetTouch(0).deltaPosition.y
, instead of Input.GetAxis("Mouse X")
and Input.GetAxis("Mouse Y")
.
Your answer
