OP unresponsive.
Pan Camera Left and Right
Mobile App - I have this working, but there is one problem. Lets say I swipe to go to the left, as soon as I lift my finger off the screen, it stops panning. So users think that its bugged because they expect it to kinda keep going and slowly stop. Instead of stoping the moment you lift your finger up. Heres my code.
using UnityEngine;
public class ScrollCamera : MonoBehaviour
{
public float dragSpeed = 1;
private Vector3 dragOrigin;
void Update()
{
if (Input.GetMouseButtonDown(0))
{
dragOrigin = Input.mousePosition;
return;
}
if (!Input.GetMouseButton(0)) return;
Vector3 pos = Camera.main.ScreenToViewportPoint(Input.mousePosition - dragOrigin);
Vector3 move = new Vector3(pos.x * dragSpeed, 0);
transform.Translate(move, Space.World);
var posi = transform.position;
posi.x = Mathf.Clamp(transform.position.x, -1.0f, 1.96f);
transform.position = posi;
}
}
What can I do to fix this so that it keeps going when you lift your finger off the screen, then slowly stops depending on how hard you swiped left or right. It needs sort of like a momentum and friction.
It does work as expected, only there is no smoothing of the movement to make it more appealing to users. ;)
Everyone expects the "smoothness" when swiping on touch devices, but it's not something they do automatically.
I googled "unity how to smooth fade velocity" and came to Vector3.SmoothDamp. That should do the trick.
Don't hesitate to google your questions, many of common problems or how-to questions (like this one) have already been answered or are even described in the documentation.
You would save time and the forums would'nt have so many duplicate questions posted.
Have a nice day :)
That's a perfect function for camera moving, thanks!
Hi, just checking if you found that my answer helped. ;) If not, or only partially, feel free to ask where you have trouble.
Please either accept the answer if it helped or feel free to ask where you still have problems with this. Don't leave questions open or ignore answers. That's rude ;)