Search Unity

Resolved Pan camera on a grid

Discussion in 'Cinemachine' started by devrandomzero, Dec 15, 2021.

  1. devrandomzero

    devrandomzero

    Joined:
    Aug 2, 2020
    Posts:
    43
    Hi everyone,
    I need some help, my project is a 2D top-down mobile game and I need a way to pan the camera.
    I've found many tutorials for click+dragging on the touch screen rts-style but what I really need is to "split" the view in a grid (for example 3x3) and move the camera screen by screen with a swipe (like when you swipe the desktops in Android).
    To be clear I'm talking about navigating the map itself, not some kind of menu.
    Can you give me some advice?
    I hope I was clear enough.
    Thank you.

    Bye
     
  2. gaborkb

    gaborkb

    Unity Technologies

    Joined:
    Nov 7, 2019
    Posts:
    856
    Hi

    I cannot help you with the input part. Have a look at their docs or try their forum. I think they have an example scene with touch inputs working.

    But once, you have the swipe event working (left, right, top, bottom). You could either swipe the maps, in this case you'll have a vcam that does not move.
    Or you can change the follow/look at targets of your vcam to look at the new map. If you'd like to have nice blends when switching you could create a vcam for each map, and then switch between the vcams on swipe events. This way, you can easily control the blend using the Default Blend setting on Cinemabrain.
     
  3. devrandomzero

    devrandomzero

    Joined:
    Aug 2, 2020
    Posts:
    43
    Thank you for or your answer, I'm sorry but I've forgot to mention that this is a 2D mobile game.

    Thank you, the controls are up and running

    That's nice, I'll keep it under consideration

    Ok, this is what I think the best approach for what I have in mind, I think that I should keep track of the position of all the vcams, right?
    Another question for this option: how can I implement a dynamic zoom in cinemachine to automatically support multiple resolution?

    Thank you again

    Bye
     
  4. gaborkb

    gaborkb

    Unity Technologies

    Joined:
    Nov 7, 2019
    Posts:
    856
    Not their position, just the vcams. For example, you could have a list of vcams -> vcam0, vcam1, vcam2, vcam3... and they would correspond to map0, map1, map2, map3... if the user swipes left, then you decrease the index, if the user swipes right, you increase the index, or vice versa.


    What would you like to achieve?
     
  5. devrandomzero

    devrandomzero

    Joined:
    Aug 2, 2020
    Posts:
    43
    Yeah, that could work, thank you.

    A while a go I saw a tutorial where the guy used a target group camera + two empty objects on the screen (one put at the far left, the other put at the far right), this allowed him to always visualize correctly every object on screen with different devices (he used the device simulator in the package manager).
    I want to achieve the same thing but in my case I have map splitted in a grid like I said before, do you think I should do the same for every single area inside the grid?

    Thank you for your help

    Bye
     
  6. devrandomzero

    devrandomzero

    Joined:
    Aug 2, 2020
    Posts:
    43
    Ok, I think it's working. For every single area I have a vcam and the 2 ancors (like I said in my previous post), when i swipe I move the index and I switch vcams. Each vcam has a reference for its own 2 ancors.
    Thank you for your help.

    Bye!
     
    gaborkb likes this.