Search Unity

  1. Looking for a job or to hire someone for a project? Check out the re-opened job forums.
    Dismiss Notice
  2. Unity 2020 LTS & Unity 2021.1 have been released.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Help Wanted Smooth, elastic, snap-to-next camera movement

Discussion in '2D' started by MinorMapillai, Feb 25, 2021.

  1. MinorMapillai

    MinorMapillai

    Joined:
    Jun 29, 2018
    Posts:
    5
    In my scene I have a basic platformer setup (back-, mid-, foregrounds etc.), and multiple "pages" which are basically the interactive part on which I'll later add things.
    At the start, the camera is looking at "Page 1". What I need to do is, if the player swipes/drgas, I need the camera to move smoothly on drag, and snap to the next page if the player swipes quickly.

    Fairside_Forum_1.jpg

    I have already implemented moving the camera with touch/drag and that works fine but I'm having trouble with the smooth snapping aspect of it. I have the points/transforms to snap to so that is not the problem.

    I have tried using dragging speed to snap but that doesn't work properly, I have tried using the camera's transform and snap to a point if it's over a certain point but even that is problematic. Specifically, in both the cases I've mentioned, the dragging continues even after snapping to the new point (since the mouse button is still down), and the origin of the click hasn't changed therefore it snaps to multiple points almost immediately and there's is no elastic/smooth movement. And, I have the snap points in a
    Transform[]
    , therefore the rapid snapping causes an index out of bounds (although I do have a check in place for that).

    In a nutshell, I need the scrolling behaviour of a ScrollRect (elasticity, snapping) on a camera. I cannot use a ScrollRect since I need the backgrounds to have parallax movement.
     
unityunity