Search Unity

  1. Calling all beginners! Join the FPS Beginners Mods Challenge until December 13.
    Dismiss Notice
  2. It's Cyber Week at the Asset Store!
    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. luispedrofonseca

    luispedrofonseca

    Joined:
    Aug 29, 2012
    Posts:
    801
    @winsock To limit the camera position you can use the Numeric Boundaries extension. Remember that you can combine multiple extensions and triggers.
     
  2. johanneskopf

    johanneskopf

    Joined:
    Feb 16, 2015
    Posts:
    52
    @luispedrofonseca
    is there a way to lock the camera on a fixed resolution (of the game) that's always visible?
    So that the camera automatically scales so that a letterbox/pillarbox is visbile, and the whole game too?
    Or do you know a better way to only make the game in one resolution and scale it up to fill the screen with the same aspect/or maybe scale it? My game is only for mobile and my camera never need to move.

    FixedResolution.PNG

    John
     
  3. flashframe

    flashframe

    Joined:
    Feb 10, 2015
    Posts:
    399
    Hi John, this might be what you're looking for:
    http://wiki.unity3d.com/index.php?title=AspectRatioEnforcer
    It works well with ProCamera2D.
     
    johanneskopf likes this.
  4. johanneskopf

    johanneskopf

    Joined:
    Feb 16, 2015
    Posts:
    52
    Hi @flashframe,
    Thanks for the answer! Got it working with that script.
    Would be cool if that would be included in ProCamera2D.
    John
     
  5. Esti2

    Esti2

    Joined:
    Dec 7, 2015
    Posts:
    2
    Hi! For some reason the panning sensibility is lower on android and it is really sensible on iOS. I mean, I have to drag a lot more to move around compared with editor. Tx!
     
    Last edited: Aug 18, 2016
  6. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,317
    Thanks for the great package.
    I'm trying to integrate Procam2D into a project and have a question of how to setup to do the following use case:

    1. Game Character being controlled by keyboard or controller and being followed by Procam2D.
    2. During game play, the player can stop controlling the character and can pan, zoom, drag with finger or mouse to see other parts of the level.
    3. When player stops panning around level and starts controlling character, the camera resumes game play and again follows player.
     
  7. Bagnol

    Bagnol

    Joined:
    Sep 5, 2013
    Posts:
    89
    @rocki I'm not 100% sure as I don't personally use the Pan and Zoom extension, but a quick look in a ProCamera2D project seemed to indicate that you could potentially have the Pan and Zoom extension component added to the camera but disabled, then when the player presses the "free look" button (or whatever trigger you use), disable character movement then enable the Pan and Zoom component on the camera, then when you want to return, disable the Pan and Zoom component and focus should return to the character.
     
    luispedrofonseca likes this.
  8. Oshigawa

    Oshigawa

    Joined:
    Jan 26, 2016
    Posts:
    255
    @luispedrofonseca

    Hello,

    i've got a noobish question, sorry about that...i'm trying to use camera shake through script in the inherited class when the enemy despawns

    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using Com.LuisPedroFonseca.ProCamera2D;
    4.  
    5. {
    6.  
    7.     public class ClassName : InheritedClassName
    8.  
    9.     public override void Despawned ()
    10.  
    11.     {
    12.  
    13.     ProCamera2DShake.Instance.Shake();
    14.  
    15.     {
    16.  
    17.     ShakeUsingPreset(string PresetName);
    18.  
    19.     }
    20.  
    21. }
    22.  
    But i get this error: Assets/Scripts/ClassName.cs(50,50): error CS1525: Unexpected symbol `PresetName', expecting `.'

    Sorry once again, i never worked with static instances.
     
    Last edited: Aug 23, 2016
  9. HolyShovel

    HolyShovel

    Joined:
    Jun 19, 2013
    Posts:
    156
    @luispedrofonseca
    Nice asset! I have one question... Can I use it in game with "Diablo" like view? Not clear top down.
     
  10. Oshigawa

    Oshigawa

    Joined:
    Jan 26, 2016
    Posts:
    255
    Well, that's 2.5D, and by the name of the asset, i guess you could :D
     
    Last edited: Aug 24, 2016
  11. HolyShovel

    HolyShovel

    Joined:
    Jun 19, 2013
    Posts:
    156
    @Kruko by name yes. But in asset store too many assets that do not do what is written in the title =)
     
  12. Bagnol

    Bagnol

    Joined:
    Sep 5, 2013
    Posts:
    89
    @Kruko I think generally 2.5D means a 2D sidescrolling platformer that uses 3D characters and/or levels. Diablo style games are generally described as isometric action RPGs.

    @mf_andreich I haven't tried to do it myself, but taking a look at the Pan and Zoom Extension page on the ProCamera2D website, it does mention that the extension is "Perfect for RTS’s", which generally use a similiar camera style to Diablo, so I can't see why it wouldn't work as long as you're using the right axes.
     
  13. Oshigawa

    Oshigawa

    Joined:
    Jan 26, 2016
    Posts:
    255
  14. HolyShovel

    HolyShovel

    Joined:
    Jun 19, 2013
    Posts:
    156
  15. Bagnol

    Bagnol

    Joined:
    Sep 5, 2013
    Posts:
    89
  16. luispedrofonseca

    luispedrofonseca

    Joined:
    Aug 29, 2012
    Posts:
    801
    Have you tried the latest version? That bug has been fixed in a recent update.

    Thanks for the suggestion! I had it on my to-do list already but I'll bump it up.

    Like @Bagnol said, you can add the PanAndZoom extension and enable it when needed. Also, remember you can add and remove camera targets at runtime.

    Your code is not properly formatted and that's why you're getting the errors. The ProCamera2D call is correct. You probably want something like this:

    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using Com.LuisPedroFonseca.ProCamera2D;
    4.  
    5. public class ClassName : InheritedClassName
    6. {
    7.     public override void Despawned ()
    8.     {
    9.          ProCamera2DShake.Instance.Shake();
    10.     }
    11. }
    12.  
     
    johanneskopf likes this.
  17. luispedrofonseca

    luispedrofonseca

    Joined:
    Aug 29, 2012
    Posts:
    801
    @mf_andreich

    To clarify, my definition of 2.5D is basically using a perspective camera on a 2D plane game. Meaning you can have 3D objects and perspective, but everything still happens on a plane.

    So, for the moment, Pro Camera 2D does not officially support "rotated top-down" cameras like in Diablo. I have plans to add support for it but it's going to take a while. It's not very straightforward.

    While it would work for the most part with the current version, some calculations might be slightly off depending on much rotated your camera is.
     
  18. Bagnol

    Bagnol

    Joined:
    Sep 5, 2013
    Posts:
    89
    @luispedrofonseca RE: Diablo perspective - I'm always hesitant to answer these types of questions in place of the asset dev for this very reason.

    On the one hand you could assume the person asking is intending to create a 3D Diablo style game and needs a proper isometric camera setup, but on the other hand they may just be looking for the ability to fake an isometric/top-down angle in on a 2D level plane like The Binding of Isaac for example. I probably should have clarified that a little better.

    I assume ProCamera2D would be suitable for the latter case?
     
  19. luispedrofonseca

    luispedrofonseca

    Joined:
    Aug 29, 2012
    Posts:
    801
    @Bagnol Yes, in that case ProCamera2D would work out-of-the-box.
     
    Bagnol likes this.
  20. geekchau

    geekchau

    Joined:
    Jun 13, 2013
    Posts:
    16
    +1 for rotated camera support (in your own time of course!)

    I have 2 scenarios which I was wondering if you or anyone can give advice on...

    1) I would like to be able to click on objects in the scene and have the camera move to focusing on it, preferably with the option of offset values.

    2) I would like some advice on combining 'panning' and 'rail'. The idea is to allow the user to pan the camera horizontally (y axis will be locked) and then use that movement to move along the rail path. Think interacting and watching a tapestry story unfolding.

    EDIT: I mean't locking any vertical gestures but in hindsight, it shouldn't matter if we assume the camera is fixed to the rail anyway.

    Thanks in advance.
     
  21. StevenWendel

    StevenWendel

    Joined:
    Jun 18, 2013
    Posts:
    105
    Hey Luís. I'm running into an issue with Boundaries Triggers. All of the others (Zoom, Rails, and Influence) work for me but I cannot get Boundaries to trigger. This is with the latest version. I even tried, as one user in this thread who had success with this same problem, in reimporting all assets. Anything come to your mind of why this might be happening? Demo scene works, I've also tried reinstalling with the empty scene process more than once.
     
    luispedrofonseca likes this.
  22. Bagnol

    Bagnol

    Joined:
    Sep 5, 2013
    Posts:
    89
    @StevenWendel Do you have a trigger boundary zone set as your starting boundaries? I just had a quick look at the demo scene and un-checking the "Set as starting boundaries" box in the first "room" seems to break all the other triggers - then stopping the scene and re-checking the box makes them work again.
     
  23. StevenWendel

    StevenWendel

    Joined:
    Jun 18, 2013
    Posts:
    105
    Ahh. This was the detail I was missing. I really appreciate you taking a look @Bagnol
     
    Bagnol likes this.
  24. Bagnol

    Bagnol

    Joined:
    Sep 5, 2013
    Posts:
    89
  25. Oshigawa

    Oshigawa

    Joined:
    Jan 26, 2016
    Posts:
    255
    @luispedrofonseca

    Hello and thank you for you answer. Sorry for disturbing you on your vacation :)
     
  26. HolyShovel

    HolyShovel

    Joined:
    Jun 19, 2013
    Posts:
    156
    I understand... its sad. So... thx for answer!
     
    luispedrofonseca likes this.
  27. luispedrofonseca

    luispedrofonseca

    Joined:
    Aug 29, 2012
    Posts:
    801
    To clarify, notice however, that you can still use ProCamera2D on a top-down game! It's just that if the rotation is different from (90, 0, 0) you'll have slight offsets depending on how far your rotation is from that.

    Hopefully on a future update I'll be able to support any kind of camera rotation and not only the XY, XZ and YZ orientations. Stay tuned!
     
  28. Kiupe

    Kiupe

    Joined:
    Feb 1, 2013
    Posts:
    528
    Hi,

    I'm trying to make Boundaries Trigger work but without success. Whether the camera or the camera target enter the trigger the boundaries are not updated. I tested to check "Set a started boundaries" to check if the boundaries were ok and they are.

    I'm pretty sure I'm doing something wrong. Is there any conditions to use the trigger ?

    Thanks
     

    Attached Files:

  29. StevenWendel

    StevenWendel

    Joined:
    Jun 18, 2013
    Posts:
    105
    I had this same problem a few posts back. Do you have a Trigger Boundary Zone set as started boundaries? You need one of these to set the boundaries and the remaining act as triggers.
     
    Bagnol likes this.
  30. Kiupe

    Kiupe

    Joined:
    Feb 1, 2013
    Posts:
    528
    No, I only have one Trigger Boundary Zone for test so far.

    Question, I have global numeric boundaries in my game. I have to have specific numeric boundaries using triggers and then be able to set back the global (using the plugin) numeric boundaries. Is that possible ? How can I do that ?

    Thanks
     
  31. Krzsiek-Siewiorek-Tate

    Krzsiek-Siewiorek-Tate

    Joined:
    Nov 17, 2015
    Posts:
    15
    Shader warning in 'Hidden/ProCamera2D/TransitionsFX/Circle': floating point division by zero at line 50 (on d3d9)
    Shader warning in 'Hidden/ProCamera2D/TransitionsFX/Circle': floating point division by zero at line 50 (on d3d11_9x)
     
  32. Bagnol

    Bagnol

    Joined:
    Sep 5, 2013
    Posts:
    89
    @Kiupe As @StevenWendel mentioned, even if you've only got one trigger boundary zone, I think you will still need to check the "Set as starting boundaries" box. There has to be at least one ProCamera2DTriggerBoundaries gameObject that has that box checked for it to work - even if you only have one in the scene.

    @Krzsiek-Siewiorek-Tate Which version of Unity are you using?
     
  33. Kiupe

    Kiupe

    Joined:
    Feb 1, 2013
    Posts:
    528
    Thanks Bagnol !

    Beside having those Trigger Boundary Zone working, is it possible to get-back to the global numeric boundary value after entering a Trigger Boundary Zone ?

    Thanks

    [EDIT]

    I tried to keep a reference to the start Trigger Boundary Zone and then call the SetBoundaries method when I want to set back its configuration. It work but the Camera size it's not reverted as it was. So, if I want to reset to the exact configuration of the start Trigger Boundary Zone, I have to se-it back and also save the Camera size and set this value back too - Am'I right ?

    Thanks
     
    Last edited: Sep 8, 2016
  34. Krzsiek-Siewiorek-Tate

    Krzsiek-Siewiorek-Tate

    Joined:
    Nov 17, 2015
    Posts:
    15
  35. luispedrofonseca

    luispedrofonseca

    Joined:
    Aug 29, 2012
    Posts:
    801
    @Kiupe Sorry for the late reply. For some reason forum notifications not always work... :/

    Can I ask what's your use case for the "global numeric boundary"? I'm currently working on a new extension (Rooms) that will solve all these annoyances with the TriggerBoundaries, which will eventually be deprecated.
    The Rooms extension will be a lot easier to setup and provide a few more options than what's currently possible with the TriggerBoundaries.


    @Krzsiek-Siewiorek-Tate Can you try to update to a newer Unity version and see if it still happens? Remember to backup.
     
  36. Kiupe

    Kiupe

    Joined:
    Feb 1, 2013
    Posts:
    528
    Hi,

    In my current game I have numeric boundaries that represent my whole level boundaries. At some points in my game I want to change those boundaries in order to restrict the camera movement and zoom in order to focus on a specific area where the player has to solve a puzzle - after the puzzle is resolved I want to restore the initial numeric boundaries and camera size.
     
  37. luispedrofonseca

    luispedrofonseca

    Joined:
    Aug 29, 2012
    Posts:
    801
    @Kiupe Thanks! I see. It makes sense. I'll make sure the Rooms extension has that use-case in mind.
    For now, you can keep using the TriggerBoundaries and do as you described in a previous post.
     
  38. Krzsiek-Siewiorek-Tate

    Krzsiek-Siewiorek-Tate

    Joined:
    Nov 17, 2015
    Posts:
    15
    @luispedrofonsec Sorry. Actually I can't. I'm working with my team on quite big project, and the pipeline is already set to this specific version. We are considering an update - but not now.
     
  39. luispedrofonseca

    luispedrofonseca

    Joined:
    Aug 29, 2012
    Posts:
    801
  40. Richardbmth

    Richardbmth

    Joined:
    Mar 5, 2016
    Posts:
    29
    Hi!

    I thought we'd share a problem we had, which we solved. Might help others or invite a better solution than ours if we've missed something obvious or ProCamera already has the functiionailty :)

    We are using the Pan extension for our vertical scrolling menu but hit a slight problem when we open a UI panel over the menu and then close it. The menu would suddenly jump on the UI panel closing. We disable the Allow Pan variable on opening the panel and then enable it again after closing the panel, so the menu doesn't scroll while you're using the panel.

    It wasn't hard to figure that the Pan exension was remembering the last place we touched, the close button on the panel. So we added a variable resetPrevTouchPoint to the Pan script and set it as true at the same time of disabling the Allow Pan variable. Script below

    Code (CSharp):
    1.  
    2.  
    3. [HideInInspector]
    4. public bool resetPrevTouchPoint = false;
    5.  
    6. ...
    7.  
    8. void Pan(float deltaTime)
    9. {
    10.  
    11. ...
    12.  
    13.   if (InsideDraggableArea(normalizedTouchPos))
    14.   {
    15.  
    16.     var prevTouchPositionWorldCoord = ProCamera2D.GameCamera.ScreenToWorldPoint(_prevTouchPosition);
    17.                  
    18.       //Added code
    19.     if (resetPrevTouchPoint){
    20.       prevTouchPositionWorldCoord = ProCamera2D.GameCamera.ScreenToWorldPoint(touchPos);
    21.       resetPrevTouchPoint = false;
    22.   } //End Added Code
    23.  
    24.       var currentTouchPositionWorldCoord = ProCamera2D.GameCamera.ScreenToWorldPoint(touchPos);
    25.       var panDelta = prevTouchPositionWorldCoord - currentTouchPositionWorldCoord;
    26.       _panDelta = new Vector2(Vector3H(panDelta), Vector3V(panDelta));
    27.  
    28.   }
    29.  
    Hope this helps.

    Richard
     
  41. luispedrofonseca

    luispedrofonseca

    Joined:
    Aug 29, 2012
    Posts:
    801
    @Richardbmth Thanks for the report!
    Your solution seems straightforward but maybe resetting that value OnDisable would be better?
     
    Richardbmth likes this.
  42. Richardbmth

    Richardbmth

    Joined:
    Mar 5, 2016
    Posts:
    29
    Thanks Luis. That makes sense, I thought there's probably something which could improve my solution. However, I like that your code is super easy to understand to be able to customize it for certain situations
     
    luispedrofonseca likes this.
  43. luispedrofonseca

    luispedrofonseca

    Joined:
    Aug 29, 2012
    Posts:
    801
    @Richardbmth I'll try to add that to the next version so you don't have to do that tweak on your side.
     
  44. joe_ftg

    joe_ftg

    Joined:
    Nov 9, 2015
    Posts:
    38
    Hi Luis

    Today I updated from 1.9.4 to 2.1.5. I found the speed based zoom no longer eases into the min and max zoom levels, instead there is a hard stop. Increasing the smoothness values slows down the camera change, but there is a still a hard stop.

    I think maybe this is because the zoom no longer slows down as it approaches the min or max, i.e. the smoothDamp is done before the min/max is taken into account.

    By looking at the previous version, I was able to modify the code to work as I expected as below. I found it easier to get it working by smoothing the target camera size (how it worked in earlier versions) rather than smoothing the size change that frame.

    in ProCamera2DSpeedBaseZoom.cs
    Code (CSharp):
    1.  
    2. public float AdjustSize(float deltaTime, float originalDelta)
    3. {
    4.             if (!enabled)
    5.                 return originalDelta;
    6.  
    7.             var newZoomAmount = 0f;
    8.  
    9.             // If the camera is bounded, reset the easing
    10.             if (_previousCamSize == ProCamera2D.ScreenSizeInWorldCoordinates.y)
    11.             {
    12.                 _prevZoomAmount = 0f;
    13.                 _zoomVelocity = 0f;
    14.             }
    15.             // Get camera velocity
    16.             CurrentVelocity = (_previousCameraPosition - VectorHV(Vector3H(ProCamera2D.LocalPosition), Vector3V(ProCamera2D.LocalPosition))).magnitude / deltaTime;
    17.             _previousCameraPosition = VectorHV(Vector3H(ProCamera2D.LocalPosition), Vector3V(ProCamera2D.LocalPosition));
    18.  
    19.             var currentSize = ProCamera2D.ScreenSizeInWorldCoordinates.y * 0.5f;
    20.             var targetSize = currentSize;
    21.             // Zoom out
    22.             if (CurrentVelocity > CamVelocityForZoomIn)
    23.             {
    24.  
    25.                 var speedPercentage = (CurrentVelocity - CamVelocityForZoomIn) / (CamVelocityForZoomOut - CamVelocityForZoomIn);
    26.                 var newSize = _initialCamSize * (1 + MaxZoomOutAmount - 1) * Mathf.Clamp01(speedPercentage);
    27.                              
    28.                 if (newSize > currentSize)
    29.                 {
    30.                     targetSize = newSize;
    31.                 }
    32.             }
    33.             // Zoom in
    34.             else
    35.             {
    36.                 var speedPercentage = (1 - (CurrentVelocity / CamVelocityForZoomIn)).Remap(0.0f, 1.0f, 0.5f, 1.0f);
    37.                 var newSize = _initialCamSize / (MaxZoomInAmount * speedPercentage);
    38.                 if (newSize < currentSize)
    39.                 {
    40.                     targetSize = newSize;
    41.                 }
    42.             }
    43.             if (Mathf.Abs(currentSize - targetSize) > .0001f)
    44.             {
    45.                 float smoothness = (targetSize < currentSize) ? ZoomInSmoothness : ZoomOutSmoothness;
    46.                 targetSize = Mathf.SmoothDamp(currentSize, targetSize, ref _zoomVelocity, smoothness, Mathf.Infinity, deltaTime);
    47.             }
    48.             var zoomAmount = targetSize - (ProCamera2D.ScreenSizeInWorldCoordinates.y / 2);
    49.  
    50.             // Save the previous zoom amount for easing purposes
    51. //            _prevZoomAmount = zoomAmount;
    52.  
    53.             // Detect if the camera size is bounded
    54.             _previousCamSize = ProCamera2D.ScreenSizeInWorldCoordinates.y;
    55.  
    56.             // Return the zoom delta - delta already factored in by SmoothDamp
    57.             return originalDelta + zoomAmount;
    58. }
    59.  
    This seems to work how I want it now, so just posting in case it's useful in any way.
    Cheers, Joe
     
  45. luispedrofonseca

    luispedrofonseca

    Joined:
    Aug 29, 2012
    Posts:
    801
    Hi Joe,

    Thanks for sharing this!

    v2.0 was a big rewrite and a few things (like this) might have slipped. I'll incorporate this into the next release (v2.2.0) which will introduce a new extension (Rooms).

    Cheers!
     
  46. tequyla

    tequyla

    Joined:
    Jul 22, 2012
    Posts:
    327
    Hello,

    could you please explain :


    thanks.

    +++
     
  47. luispedrofonseca

    luispedrofonseca

    Joined:
    Aug 29, 2012
    Posts:
    801
    @tequyla It meant that I'm going to include the fix reported by @joe_ftg in the next release. The next release will also include a new extension called Rooms. I'm going to share more details about it very soon.
     
  48. tequyla

    tequyla

    Joined:
    Jul 22, 2012
    Posts:
    327
  49. luispedrofonseca

    luispedrofonseca

    Joined:
    Aug 29, 2012
    Posts:
    801
    @tequyla Not exactly sure what kind of features you're looking for from that asset. Any how, look at my next post for a preview on the new Rooms extension.
     
  50. luispedrofonseca

    luispedrofonseca

    Joined:
    Aug 29, 2012
    Posts:
    801
    Hi guys,

    As promised here's a quick preview of the new extension - Rooms!



    Would really appreciate your feedback! As always, if you'd like access to a preview version before it's released on the Asset Store please get in touch.