Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We’re making changes to the Unity Runtime Fee pricing policy that we announced on September 12th. Access our latest thread for more information!
    Dismiss Notice
  3. Dismiss Notice

[RELEASED] Pro Camera 2D - The definitive 2D & 2.5D Unity camera plugin

Discussion in 'Assets and Asset Store' started by luispedrofonseca, Jul 29, 2015.

  1. crafTDev

    crafTDev

    Joined:
    Nov 5, 2008
    Posts:
    1,818
    Hello,

    This may be it but let me show an example of what I am trying to convey:

    Full Zoomed Out:
    upload_2019-8-29_0-39-39.png

    Zoomed In:
    checkeredzoom.png

    Zoomed In Fit:
    checkeredzoomfixed.png

    Do these images help to understand what I mean? After Zooming/Panning I want the camera to adjust to fit full square (in this case; Rooms? If thats how it should actually be done...). I don't want it to look like the second pic, it should be the third.

    Thanks,
    jrDev
     
  2. luispedrofonseca

    luispedrofonseca

    Joined:
    Aug 29, 2012
    Posts:
    924
    @jrDev You can use the "UpdateScreenSize" method and pass whatever size your cells have.

    As for Playmaker actions, there are a few more common ones, but they don't cover all extensions. If I'm not mistaken though, Playmaker can always use generic method calling?
     
  3. Emphy

    Emphy

    Joined:
    Feb 7, 2014
    Posts:
    33
    Hi! Just curious: with the new (experimental) 2D LWRP, stacking cameras seems to be a problem. Might this be why parallax doesn't work? I am 99% sure the setup is correct in my scene. If so, any idea if there is a fix (yet)?
     
  4. luispedrofonseca

    luispedrofonseca

    Joined:
    Aug 29, 2012
    Posts:
    924
    @Emphy Yes, that's correct. Until Unity decides how they're going to support stacking cameras, the parallax extension won't work with the new SRP's. I'm keeping an eye on the issue and I'll add support as soon as possible.
     
  5. Emphy

    Emphy

    Joined:
    Feb 7, 2014
    Posts:
    33
    Thank you. Sadly I've come to the same conclusion after browsing issue reports about LWRP. Seems like Unity should've added this already but yeah, it is what it is.

    For anyone interested: https://forum.unity.com/threads/glitching-with-multiple-cameras-lwrp.592477/page-2#post-4479097
     
  6. crafTDev

    crafTDev

    Joined:
    Nov 5, 2008
    Posts:
    1,818
    That sounds great!

    And yeah, there is a Method Call action.

    Thanks,
    jrDev
     
  7. Nihil688

    Nihil688

    Joined:
    Mar 12, 2013
    Posts:
    503
    Is there an example as to how to create an infinite loop when using parallax? Aka I reach the end of the map and I see the start of it creating a "looped" world without losing the parallax effect.
     
    Last edited: Aug 31, 2019
  8. luispedrofonseca

    luispedrofonseca

    Joined:
    Aug 29, 2012
    Posts:
    924
    Nihil688 likes this.
  9. Nihil688

    Nihil688

    Joined:
    Mar 12, 2013
    Posts:
    503
    @luispedrofonseca I saw that but I didn't understand how it works. I don't want to repeat just the background. I want when I reach the far right side of the screen, to continue on it's left side. In a way have a round earth so to speak
     
  10. luispedrofonseca

    luispedrofonseca

    Joined:
    Aug 29, 2012
    Posts:
    924
    @Nihil688 Have you taken a look at the included Repeater demo scene?
    You basically pass it a GameObject, define its size, and the extension takes care of repeating it for you in any direction, if you choose to do so.

    Regarding the entering one side and exiting the other, maybe you could accomplish it with the Rooms extension? Hard to tell without knowing exactly what you're trying to accomplish.
     
    Nihil688 likes this.
  11. Nihil688

    Nihil688

    Joined:
    Mar 12, 2013
    Posts:
    503
    I played around with the scene a bit more and got how it works now thanks. Maybe in your example scene you should use the stage and the mountains on the background instead of that semi transparent image. Could show better how it should work.
     
    luispedrofonseca likes this.
  12. esteban16108

    esteban16108

    Joined:
    Jan 23, 2014
    Posts:
    158
    @luispedrofonseca Hi, I want to use the Parallax Extension to do an Infinite Parallax, the thing is that my camera is always moving upwards, is there a way to have the parallax extension repeat the layer? I checked the repeater extension but it doesn't take care of the speed.

    Any way to achieve infinite parallax on a direction?

    Thanks.
     
  13. luispedrofonseca

    luispedrofonseca

    Joined:
    Aug 29, 2012
    Posts:
    924
    @esteban16108 When you have the Parallax extension enabled, the Repeater extension will ask you which camera you want to use. Simply choose the corresponding parallax camera and you should be good to go.
     
  14. esteban16108

    esteban16108

    Joined:
    Jan 23, 2014
    Posts:
    158
    @luispedrofonseca Thanks.

    Another question, I have this Camera following the Player in a vertical jumper, is there a way to limit the velocity of the camera when going down? The Object that kills the player is attached at the end of the camera and when the player falls the camera follows fast and takes a little to touch the kill object.

    Thanks.
     
  15. luispedrofonseca

    luispedrofonseca

    Joined:
    Aug 29, 2012
    Posts:
    924
    @esteban16108 You can adjust the "Follow Smoothness Y" to fit your needs. There's no way to separate the speed by up and down directions as that would look weird, but adjusting the Y speed should be all you need.
     
  16. esteban16108

    esteban16108

    Joined:
    Jan 23, 2014
    Posts:
    158
    @luispedrofonseca Implemented something like the LimitSpeed extension but hijacking the vertical delta when it's < 0 and that works, the extensions made it really easy. Thanks.
     
    luispedrofonseca likes this.
  17. davecdempsey

    davecdempsey

    Joined:
    Feb 28, 2017
    Posts:
    4
    @luispedrofonseca Has this been figured out? I am very interested in using ProCamera2D for this exact purpose. I know I could slice up the rooms into multiple rects, but it is not ideal.
     
  18. luispedrofonseca

    luispedrofonseca

    Joined:
    Aug 29, 2012
    Posts:
    924
    @davecdempsey There's no support for "polygonal rooms" because that introduces a lot of weird edge cases. You can try to look at the "Geometry Boundaries" extension as that might give the results you're looking for.
     
  19. jwvanderbeck

    jwvanderbeck

    Joined:
    Dec 4, 2014
    Posts:
    820
    Trying out the new (to me at least) Pan and Zoom extension to see if I can just replace my custom hacked together stuff.

    It seems easy enough to use but a bit basic. Any chance of some additional features in this extension such as:
    1) Inverting zoom and pan directions. The current setup seems to be exactly opposite of what I'd expect.
    2) Scaling zoom and pan speed based on zoom "level". As you zoom in on a map moving you need to scale back your pan and zoom speeds or else control becomes very hard. In my custom hack I did this by having two values for pan speed and two values for zoom speed, then lerping between each based on current zoom factor to determine the "current" pan and zoom speeds.
     
  20. luispedrofonseca

    luispedrofonseca

    Joined:
    Aug 29, 2012
    Posts:
    924
    @jwvanderbeck

    1) To invert the direction you just have to change the speed signal (negative or positive).
    2) Can you show me an example of a game that does this well? Or maybe show me your previous solution?
     
  21. jwvanderbeck

    jwvanderbeck

    Joined:
    Dec 4, 2014
    Posts:
    820
    When I started doing this I googled around but honestly couldn't find much on the topic. It seems like everyone just assumes everyone does it but no one talks about it :p I wouldn't say what I did was "done well" but I can show that.

    The problem that is trying to be solved here is that if you have one speed say when zoomed way out that works well, when you zoom way in now the speed is way too twitchy and hard to control. If you instead have a speed that works well when zoomed way in, then when zoomed way out moving the camera large distances is very slow.

    Below is my implementation but bear in mind it is nothing but a quick hack to get a working camera in. It was built in no joke about an hour total and is far from perfect overall, but the variable rates work pretty well.

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.InputSystem;
    3.  
    4. public class MapCamera : MonoBehaviour
    5. {
    6.  
    7.     public Vector2 panSpeed = new Vector2(100, 1000);
    8.     public Vector2 zoomSpeed = new Vector2(100, 1000);
    9.     public Vector2 zoomExtents = new Vector2(-40, -2000);
    10.  
    11.     private Vector2 panDelta;
    12.     private float zoomDelta;
    13.  
    14.     // Update is called once per frame
    15.     void Update()
    16.     {
    17.         Vector3 zoom = CalculateZoom(Time.deltaTime);
    18.         Vector3 pan = CalculatePan(Time.deltaTime);
    19.      
    20.         transform.position += zoom + pan;
    21.     }
    22.  
    23.     private float CurrentZoomFactor()
    24.     {
    25.         // calculate a zoom factor that represents how far between zoomExtents. and zoomExtents.y we are currently
    26.         float z = transform.position.z;
    27.         float zoomFactor = Remap(z, zoomExtents.x, zoomExtents.y, 0f, 1f);
    28.         return zoomFactor;
    29.     }
    30.     private Vector3 CalculateZoom(float deltaTime)
    31.     {
    32.         float zoomFactor = CurrentZoomFactor();
    33.         float currentZoomSpeed = Mathf.Lerp(zoomSpeed.x, zoomSpeed.y, zoomFactor);
    34.         var cachedTransform = transform;
    35.         Vector3 zoom = deltaTime * zoomDelta * currentZoomSpeed * cachedTransform.forward;
    36.         Vector3 newPosition = cachedTransform.position + zoom;
    37.         if (newPosition.z > zoomExtents.x)
    38.         {
    39.             // since we deal with negative numbers here, this means we're past the maximum zoom extent
    40.             // "Back up" along the -forward vector however many units ahead we went
    41.             float overshoot = newPosition.z - zoomExtents.x;
    42.             zoom += -cachedTransform.forward * overshoot;
    43.         }
    44.         else if (newPosition.z < zoomExtents.y)
    45.         {
    46.             // zoomed out past minimum extent
    47.             // move along forward vector enough units to get back inside extents
    48.             float overshoot = zoomExtents.y - newPosition.z;
    49.             zoom += cachedTransform.forward * overshoot;
    50.         }
    51.         return zoom;
    52.     }
    53.  
    54.     private Vector3 CalculatePan(float deltaTime)
    55.     {
    56.         float zoomFactor = CurrentZoomFactor();
    57.         float currentPanSpeed = Mathf.Lerp(panSpeed.x, panSpeed.y, zoomFactor);
    58.         Vector3 pan = deltaTime * currentPanSpeed * new Vector3(panDelta.x, panDelta.y, 0);
    59.  
    60.         return pan;
    61.     }
    62.  
    63.     private static float Remap(float value, float low1, float high1, float low2, float high2)
    64.     {
    65.         return low2 + (value - low1) * (high2 - low2) / (high1 - low1);
    66.     }
    67.  
    68.     public void Pan(InputAction.CallbackContext context)
    69.     {
    70.         panDelta = context.ReadValue<Vector2>();
    71.     }
    72.  
    73.     public void Zoom(InputAction.CallbackContext context)
    74.     {
    75.         zoomDelta = context.ReadValue<float>();
    76.     }
    77. }
    78.  
     
  22. jwvanderbeck

    jwvanderbeck

    Joined:
    Dec 4, 2014
    Posts:
    820
    I think what I might try for now is implementing some sort of invisible puck that the player controls to move the camera, and set that as the camera target.

    Basically I am prototyping a game that has no actual player character, so I'm looking at different ways to allow a player to manipulate the camera view on a vary large map.
     
  23. luispedrofonseca

    luispedrofonseca

    Joined:
    Aug 29, 2012
    Posts:
    924
    That's essentially what the PanAndZoom extension does. Feel free to have a look at the source code and create your own extension based on it.
     
  24. DavidJares

    DavidJares

    Joined:
    Dec 18, 2016
    Posts:
    50
    Helllo. Can I make the camera follow a target along an axis in a positive direction, but stop / not follow the player when the player moves back in the oppsotie direction ? ( so that the level is like a one-way-street :) ? thank you in advance
     
  25. luispedrofonseca

    luispedrofonseca

    Joined:
    Aug 29, 2012
    Posts:
    924
    @DavidJares That behaviour is not built-in because it's too specific. But you can easily accomplish it by creating an invisible camera target (empty GameObject) and make it only follow your player if he's moving forward.
     
    DavidJares likes this.
  26. Erpkins

    Erpkins

    Joined:
    Nov 22, 2019
    Posts:
    1
    Hey Luis, my team and I have been using the plugin and we've been enjoying how versatile the tool is. We're running into a problem specifically with the Trigger Bounds, as it seems to jitter and jump between triggers for no apparent reason. I thought at first it might be going from one camera with a top boundary to another without a top boundary caused the issue, but it seems to not really matter how the zones are configured. I was wondering if there might be something causing this as having smooth transitions in our game would be ideal
     
  27. luispedrofonseca

    luispedrofonseca

    Joined:
    Aug 29, 2012
    Posts:
    924
    @Erpkins Thanks for using ProCamera2D. Please use the support page on the website to contact me and I'll help you out. There shouldn't be any jitters or stutters when transitioning between different boundaries.
     
  28. digiwombat

    digiwombat

    Joined:
    Sep 26, 2013
    Posts:
    44
    Hey man!

    Just recently updated to the Universal Render Pipeline and now my TransitionFX have stopped working. They seem to be functioning behind the scenes as far as I can tell, but they are not drawing to camera. My best guess without digging in too deep is that maybe the shader driving the change doesn't play nice with the new rendering pipeline?

    Any assistance is appreciated. :D
     
  29. luispedrofonseca

    luispedrofonseca

    Joined:
    Aug 29, 2012
    Posts:
    924
    Hi @digiwombat,

    Unfortunately the new SRP's are still very early and their API is a moving target. Stuff like camera stacking and other features are not present yet so it makes the TransitionsFX and Parallax extensions unsupported for the time being under those pipelines.

    I do plan to update once things settle down, but not before. Until then my recommendation is to stick to the default renderer or find another alternative for the transitions.
     
  30. SirStompsalot

    SirStompsalot

    Joined:
    Sep 28, 2013
    Posts:
    112
    Hi Luis, been using ProCamera for a while and loving it.

    Curious, is there a way to get the zoom extension's zoom details, and reapply them? I'm trying to save the camera position (which I have covered) and zoom details to a binary file to reload them later, but having trouble finding the properties in the extension.

    Thanks!
     
  31. luispedrofonseca

    luispedrofonseca

    Joined:
    Aug 29, 2012
    Posts:
    924
    @SirStompsalot I'm a bit confused with what you're trying to accomplish. Can you please explain further?
     
  32. SirStompsalot

    SirStompsalot

    Joined:
    Sep 28, 2013
    Posts:
    112
    Sure thing! What I'm trying to do is save the position of the camera. I.e. something like this:
    Code (CSharp):
    1. private void Awake()
    2. {
    3.     cam = Camera.main;
    4.     GameSave.LoadSave();
    5.     if(GameSave.save.Player.CurrentWorldCameraPosition != Vector3.zero)
    6.     {
    7.         cam.transform.position = GameSave.save.Player.CurrentWorldCameraPosition;
    8.     }
    9. }
    10.  
    11. public void Save()
    12. {
    13.     GameSave.save.Player.CurrentWorldCameraPosition = cam.transform.position;
    14.     GameSave.WriteSave();
    15. }
    The problem is when the player loads from a save. The zoom appears to persist, but when they try to zoom again (with the Pan/Zoom extension) the zoom level.. resets? It's initially jumpy.

    I have a feeling this is due to the Pan/zoom extension having a default zoom level. Is there a way to sync the zoom from the camera position, or is there properties I should be setting?
     
  33. luispedrofonseca

    luispedrofonseca

    Joined:
    Aug 29, 2012
    Posts:
    924
    @SirStompsalot Thanks for clarifying. You can "reset" the PanAndZoom extension to grab the initial camera values (that you set by code) by re-enabling the component. Something like this:

    Code (csharp):
    1. private void Start()
    2. {
    3.     myPanAndZoom.enabled = false;
    4.     myPanAndZoom.enabled = true;
    5. }
     
  34. SirStompsalot

    SirStompsalot

    Joined:
    Sep 28, 2013
    Posts:
    112
    Yup, wouldn't have tried that in a million years. Thanks so much for the help!
     
    luispedrofonseca likes this.
  35. SirStompsalot

    SirStompsalot

    Joined:
    Sep 28, 2013
    Posts:
    112
    That didn't seem to do it I'm afraid. I set the camera position, disable then reenable the ProCamera2DPanAndZoom component. Upon first zoom the camera seems to snap back to the default zoom level. Any other ideas?
     
  36. luispedrofonseca

    luispedrofonseca

    Joined:
    Aug 29, 2012
    Posts:
    924
    @SirStompsalot That's weird. Please try doing it a frame later in a coroutine Start method. Like this:

    Code (csharp):
    1. private IEnumerator Start()
    2. {
    3.    yield return null;
    4.    myPanAndZoom.enabled = false;
    5.    myPanAndZoom.enabled = true;
    6. }
     
  37. SirStompsalot

    SirStompsalot

    Joined:
    Sep 28, 2013
    Posts:
    112
    Yeah, I'd had that thought as well. I even tried disabling the component on my camera within the editor, and enabling it after setting the camera position, that didn't work either. Upgraded to the latest version of PC2D, no change.

    Sorry to be a pest. Any other ideas?
     
  38. luispedrofonseca

    luispedrofonseca

    Joined:
    Aug 29, 2012
    Posts:
    924
    @SirStompsalot Can you please send me through PM a sample project that replicates the issue you're having?
     
  39. esteban16108

    esteban16108

    Joined:
    Jan 23, 2014
    Posts:
    158
    @luispedrofonseca Hi, just imported the asset (Latest version from the Asset store) on a new project using 2019.2.15 and got this message:

    Failed to load 'C:/UnityProjects/Up/Assets/ProCamera2D/Examples/TopDownShooter/Scenes/TopDownShooter/NavMesh.asset' because it was serialized with a newer version of Unity. (Has a higher SerializedFile version)

    Any clue how to fix this?
     
  40. luispedrofonseca

    luispedrofonseca

    Joined:
    Aug 29, 2012
    Posts:
    924
    @esteban16108 I'm guessing for some reason Unity is giving the version I exported with Unity 2019.3 and that introduced some changes on the serialization.
    What happens if you right-click it and import it again?
     
  41. Emphy

    Emphy

    Joined:
    Feb 7, 2014
    Posts:
    33
    @luispedrofonseca Just wondering: using Corgi2D here and it already has like 27 layers used for all the game objects it uses. So that would mean I only have 4 layers for Parallax camera culling using PC2D? Is there an obvious way to make "unlimited" parallax layers for the background + foreground?
     
  42. luispedrofonseca

    luispedrofonseca

    Joined:
    Aug 29, 2012
    Posts:
    924
    @Emphy There's no issue in reusing layers for configuring the Parallax extension. I'm curious though, why do you have 27 layers in usage? Have you taken a look at tags or maybe even sorting layers?
     
  43. Emphy

    Emphy

    Joined:
    Feb 7, 2014
    Posts:
    33
    The Corgi2D plugin uses 27 layers by default, not sure it's needed - but was just thinking. But yeah, I'm gonna have to make do with the 31 layers? Just wondering how that works if you have really complex scenes with like 3 foreground and 7 background parallax layers. But maybe I'm exaggerating?
     
  44. luispedrofonseca

    luispedrofonseca

    Joined:
    Aug 29, 2012
    Posts:
    924
    @Emphy That honestly sounds overkill but there's no problem at all. You simply have to reuse the same layers for the parallax layers. They won't conflict in any way.
     
  45. The_Arrival

    The_Arrival

    Joined:
    Dec 3, 2014
    Posts:
    82
    Minor "Bug"-Report,

    i just imported 2D Camera to my new project and got 14 pre-compile errors. I had no Timeline package in my project. Maybe there is a way for you to auto-resolve dependencies from unity packages
     
  46. luispedrofonseca

    luispedrofonseca

    Joined:
    Aug 29, 2012
    Posts:
    924
    @The_Arrival Thanks for the report. That's a great catch. Timeline used to come bundled into the editor but now it's a separate package. I'll need to find a way around it. I'll solve it in the next update.
     
  47. Emphy

    Emphy

    Joined:
    Feb 7, 2014
    Posts:
    33
    Is there a workaround on the TransitionsFX not covering the parallax layers with speed > 1? They automatically get a start depth of the camera depth + 1 so the transition is working but the front parallax layers are always visible.

    ----------------------------------------------

    And another weird thing, if I spawn an object and want to place the camera on it via a script, it always uses the smooth but I need it to be instant. So in my script:

    _camera.AddCameraTarget(player.transform);
    _camera.MoveCameraInstantlyToPosition(player.transform.position);

    I tried setting the smoothing to 0 then setting it to 0.30 after the MoveCameraInstantlyToPosition but yeah, does not seem to work. Is there an easy way to just place it at the correct position?


    Vector3 pos = new Vector3(player.transform.position.x, player.transform.position.y, _camera.transform.position.z);
    _camera.transform.position = pos;

    Even this doesn't do it ;)
     
    Last edited: Dec 19, 2019
  48. luispedrofonseca

    luispedrofonseca

    Joined:
    Aug 29, 2012
    Posts:
    924
    @Emphy For the Transitions FX to work on all cameras you need to apply it to the topmost camera. In your case you'll need to look at the cameras that are created for the parallax layers and choose the fastest (topmost) one and add the script in there.

    As for that other issue with the camera not moving instantly, that's weird. That method you're calling "MoveCameraInstantlyToPosition" is exactly for that. Please send me through PM a small sample project that replicates the issue so I can have a look.
     
  49. Emphy

    Emphy

    Joined:
    Feb 7, 2014
    Posts:
    33
    Alright, let me try that. Also, it might be due to the numeric boundaries that it might not work- something with setting a position it should not be able to reach..? I will try something out and get back to you :)

    Edit: Okay yeah it does seem to work like expected... hmm. I guess I made the error of making the cam go outside its boundaries so it compensated afterwards.
     
    Last edited: Dec 19, 2019
    luispedrofonseca likes this.
  50. luispedrofonseca

    luispedrofonseca

    Joined:
    Aug 29, 2012
    Posts:
    924
    Yes, if you're trying to send the camera to a place outside of its boundaries, it will try to get back inside. Please notice you can disable the boundaries at runtime if needed though.