GMS 2 Camera "Jumping" Back, Mobile Camera Drag Gesture

Discussion in 'Programming' started by twalkerp, Aug 13, 2019.

  1. twalkerp

    twalkerp Member

    Joined:
    Oct 12, 2018
    Posts:
    29
    I'm trying to create mobile camera drag, so once the user zooms in they can drag around the room and view different parts.

    It works, but the camera jumps around when dragging, it doesn't feel smooth at all, have to swipe around a bunch to move the camera.

    It's like two steps forward one step back.


    This is my current code in Global Gesture Drag Start:
    Code:
    drag_room_x = event_data[? "posX"];
    drag_room_y = event_data[? "posY"];
    
    This is my current code in Global Gesture Dragging
    Code:
     _x = drag_room_x - event_data[? "rawposX"];
     _y = drag_room_y - event_data[? "rawposY"];
    camera_set_view_pos(cam,_x,_y);
    
    Thanks!
     
  2. curato

    curato Member

    Joined:
    Jun 30, 2016
    Posts:
    431
    you can't move it to the camera position to the destination all at once if you don't want the snap. you need to look at where the camera is and where you drug to and move toward the destination. I have gradual move camera in my project. I take the x and y differential of where the camera is and where I want it and divide those numbers by 25 (to avoid the snap bigger is slower) and as long as the numbers don't match then keep move it every frame until you get there. The point is your can't do it all in the same frame or you will get the snap.

    In your particular case, if you don't start dragging from the camera origin you will get a jump in the first frame if you aren't close.
     
  3. twalkerp

    twalkerp Member

    Joined:
    Oct 12, 2018
    Posts:
    29
    Thanks!!

    Here is the working solution for anyone looking in the future

    Code:
    camX = camera_get_view_x(cam);
    camY = camera_get_view_y(cam);
    
    drag_room_x = camX + event_data[? "rawposX"];
    drag_room_y = camY + event_data[? "rawposY"];
    
     
  4. krugen

    krugen Member

    Joined:
    Jan 24, 2019
    Posts:
    180
    Hi, where should I put this?

    If I put this in global dragging, what should I put in global drag start?
     
  5. krugen

    krugen Member

    Joined:
    Jan 24, 2019
    Posts:
    180
    it's really sad man
     
  6. Leandro Genske

    Leandro Genske Member

    Joined:
    Oct 18, 2019
    Posts:
    5
    Thank you so much!
    Just remembering that this code goes at Global Drag Start
     
  7. Leandro Genske

    Leandro Genske Member

    Joined:
    Oct 18, 2019
    Posts:
    5
    Global Drag Start
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice