Search Unity

[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:
    945
    @BharatThreye At the moment that's not possible. But it's actually a very good suggestion. I'll see what's possible.
     
  2. luispedrofonseca

    luispedrofonseca

    Joined:
    Aug 29, 2012
    Posts:
    945
    v1.7.3 is now up!

    • Added a method (TestTrigger) to the BaseTrigger class that allows to manually force the trigger collision test
    • Added a method (AddCinematicTarget) to the Cinematics extension that allows to manually add a new cinematic target at runtime
    • Added a method (AddRailsTarget) to the Rails extension that allows to manually add a new rails target at runtime
    • Fixed a bug that could cause a null reference after destroying an object that had a ProCamera2D extension
     
  3. luispedrofonseca

    luispedrofonseca

    Joined:
    Aug 29, 2012
    Posts:
    945
    @BharatThreye I've implemented the feature you requested but I'd like to get your feedback before releasing it. Can you please get in touch so I can send you a beta?
     
  4. nunesbarbosa

    nunesbarbosa

    Joined:
    Jul 17, 2012
    Posts:
    103
    Any clues on how to make an infinite parallax based on the speed values?
    I have 5 parallax backgrounds on those speed values:
    0, 0.2, 0.55, 0.8, 1.3

    And I need to know at which point I need to create a new background image when the player moves to the right for example but progressivelly for all 4 moving backgrounds.

    I failing on doing the math right.
     
  5. luispedrofonseca

    luispedrofonseca

    Joined:
    Aug 29, 2012
    Posts:
    945
    @nunesbarbosa I'm actually currently working on something like that by request of another client. I'll keep you posted as well once I have more information on it.
     
  6. nunesbarbosa

    nunesbarbosa

    Joined:
    Jul 17, 2012
    Posts:
    103
    I couldn't wait and made my own solution. I hope it helps on the solution and for those who couldn't wait.
    You need one prefab for each parallax background and the matching parallax camera (not the main camera).
    I can't send the ObjectPoolingManager class but you can replace with your own Object polling. Hope it helps!

    InfiniteParallax.png

    Code (CSharp):
    1. using System;
    2. using UnityEngine;
    3.  
    4. public class Background : MonoBehaviour {
    5.     private const int BG_OBJECTS = 3;
    6.     private const float BACKGROUND_DISTANCE = 42.66f;
    7.  
    8.     private float vertExtent;
    9.     private float horzExtent;
    10.    
    11.     public float rightBound;
    12.     public float leftBound;
    13.  
    14.     public SpriteRenderer[] spriteRendererPrefabs;
    15.     public Camera[] cameras;
    16.     private SpriteRenderer[,] spriteRenderers;
    17.  
    18.     void Start() {
    19.         spriteRenderers = new SpriteRenderer[spriteRendererPrefabs.Length,BG_OBJECTS];
    20.  
    21.         vertExtent = Camera.main.orthographicSize;
    22.         horzExtent = vertExtent * Screen.width / Screen.height;
    23.  
    24.         SpriteRenderer spriteBounds = spriteRendererPrefabs [0];
    25.         leftBound = (float)(horzExtent - spriteBounds.sprite.bounds.size.x / 2.0f);
    26.         rightBound = (float)(spriteBounds.sprite.bounds.size.x / 2.0f - horzExtent);
    27.         PreparePoolBackground ();
    28.  
    29.         for (int i = 0; i<spriteRendererPrefabs.Length; i++)
    30.         {
    31.             for (int j = 0; j< BG_OBJECTS; j++) {
    32.                 spriteRenderers[i,j] = SpawnSpriteRendererPrefab (i);
    33.                 spriteRenderers[i,j].gameObject.SetActive (true);
    34.                 if(j > BG_OBJECTS/2) {
    35.                     spriteRenderers[i,j].transform.position = Vector2.right * BACKGROUND_DISTANCE * (j - BG_OBJECTS/2);
    36.                 }
    37.                
    38.                 if(i < BG_OBJECTS/2) {
    39.                     spriteRenderers[i,j].transform.position = Vector2.left * BACKGROUND_DISTANCE * (BG_OBJECTS/2 - j);
    40.                 }
    41.             }
    42.         }
    43.  
    44.     }
    45.  
    46.     void PreparePoolBackground()
    47.     {
    48.         for (int i = 0; i<spriteRendererPrefabs.Length; i++)
    49.         {
    50.             for (int j = 0; j<BG_OBJECTS; j++) {
    51.                 ObjectPoolingManager.Instance.CreatePool(spriteRendererPrefabs[i].gameObject, BG_OBJECTS, BG_OBJECTS);
    52.                
    53.                 var allBgs = ObjectPoolingManager.Instance.GetObjects(spriteRendererPrefabs[i].gameObject.name);
    54.                
    55.                 foreach (var d in allBgs)
    56.                 {
    57.                     d.transform.rotation = Quaternion.identity;
    58.                     d.transform.localScale = Vector3.one;
    59.                    
    60.                     d.transform.parent = transform;
    61.                     d.transform.position = Vector2.zero;
    62.                    
    63.                     d.SetActive(false);
    64.                 }
    65.             }
    66.         }
    67.     }
    68.  
    69.     public SpriteRenderer SpawnSpriteRendererPrefab(int bgPos)
    70.     {
    71.         var o = ObjectPoolingManager.Instance.GetObject (spriteRendererPrefabs [bgPos].name).GetComponent<SpriteRenderer> ();
    72.         return o;
    73.     }
    74.  
    75.     void LateUpdate() {
    76.         Reposition ();
    77.     }
    78.  
    79.     public void Reposition ()
    80.     {
    81.         for (int i = 0; i < spriteRendererPrefabs.Length; i++) {
    82.             SpriteRenderer sr = spriteRenderers[i, BG_OBJECTS/2];
    83.             Camera cam = cameras[i];
    84.  
    85.             if(cam.transform.position.x > sr.transform.position.x + rightBound) {
    86.                 spriteRenderers[i,0].transform.position = spriteRenderers[i,BG_OBJECTS - 1].transform.position + Vector3.right * BACKGROUND_DISTANCE;
    87.                
    88.                 SpriteRenderer aux = spriteRenderers[i,0];
    89.                
    90.                 for (int j = 0; j< BG_OBJECTS - 1; j++) {
    91.                     spriteRenderers[i,j] = spriteRenderers[i,j+1];
    92.                 }
    93.                 spriteRenderers[i,BG_OBJECTS - 1] = aux;
    94.             }
    95.  
    96.             if(cam.transform.position.x < sr.transform.position.x - leftBound) {
    97.                 spriteRenderers[i,BG_OBJECTS - 1].transform.position = spriteRenderers[i,0].transform.position + Vector3.left * BACKGROUND_DISTANCE;
    98.                
    99.                 SpriteRenderer aux = spriteRenderers[i,BG_OBJECTS - 1];
    100.                
    101.                 for (int j = BG_OBJECTS - 1; j> 0; j--) {
    102.                     spriteRenderers[i,j] = spriteRenderers[i,j-1];
    103.                 }
    104.                 spriteRenderers[i,0] = aux;
    105.             }
    106.         }
    107.     }
    108. }
    109.  
     
    luispedrofonseca likes this.
  7. luispedrofonseca

    luispedrofonseca

    Joined:
    Aug 29, 2012
    Posts:
    945
    Thanks for sharing @nunesbarbosa!

    The solution I'm currently working on won't be directly tied to parallax, since it will work with any camera. It will also work with any kind of GameObject. Still on the research phase though. I'll post it here once it's ready.
     
    nunesbarbosa likes this.
  8. luispedrofonseca

    luispedrofonseca

    Joined:
    Aug 29, 2012
    Posts:
    945
    nunesbarbosa, Mr-Stein and flashframe like this.
  9. flashframe

    flashframe

    Joined:
    Feb 10, 2015
    Posts:
    798
    Very cool!
     
    luispedrofonseca likes this.
  10. Mr-Stein

    Mr-Stein

    Joined:
    Dec 4, 2013
    Posts:
    169
    amazing! I already retweet with my bots :)
     
    luispedrofonseca likes this.
  11. jwvanderbeck

    jwvanderbeck

    Joined:
    Dec 4, 2014
    Posts:
    825
    Hi there. I am really stuck trying to get the effect I am going for with ProCamera2D. I thought this would be simple but no matter how I try it, it never looks the way I envisioned.

    Essentially I am trying to use the camera in a very simple way. I have a gameboard seen from overhead. There are essentially 3 ways I want the player to be able to vide the board, and I am trying to use this camera to move between them.

    The first view is overview and shows the entire gameboard.
    The second view is area view which zooms in and pans the camera to a sort of medium shot of a particular part of the gameboard
    The third view is planet view which pans and zooms in to a specific planet

    Now my intent was to use ProCamera2Ds influence triggers in a sort of manual mode to trigger both a pan and a zoom to my view target. This works, but doesn't give me the feel I had in my mind. In my mind I see the zoom and pan happening together in a seamless way so that you don't really notice the pan so much, but rather from the POV of the player it seems like it just zoomed on on a point on the board. Essentially I want it to work in the same way you would see in a game where you "zoom to cursor" if that makes sense?
     
  12. flashframe

    flashframe

    Joined:
    Feb 10, 2015
    Posts:
    798
    @jwvanderbeck Have you tried using multiple cameras and switching between them instead of using influence triggers? You can use the Cinematics plugin in ProCamera2D to switch between different cameras.
     
    luispedrofonseca likes this.
  13. jwvanderbeck

    jwvanderbeck

    Joined:
    Dec 4, 2014
    Posts:
    825
    No but I can't see that giving me the effect I want either. I want it to appear as though it is a single camera not switching been cameras.
     
  14. luispedrofonseca

    luispedrofonseca

    Joined:
    Aug 29, 2012
    Posts:
    945
  15. flashframe

    flashframe

    Joined:
    Feb 10, 2015
    Posts:
    798
    The Cinematic plugin lerps/animates from one camera position to another over time, so it will give you the effect you are looking for. But obviously I would defer to @luispedrofonseca since he made the asset. His method will work best I'm sure.
     
  16. jwvanderbeck

    jwvanderbeck

    Joined:
    Dec 4, 2014
    Posts:
    825
    Yeah this is what I have done but the problem is how it feels. It feels very much like a camera moving from one point to another and then pushing in. Which isn't what I want. At least it doesn't feel right.

    Ok perfect example. Open up Google maps and zoom all the way out. Then place your mouse cursor over a spot on the map off near the edges, and zoom in with your mousewheel. See how it zooms to the cursor, but there isn't a sense of a camera repositioning? That is the feel I want.

    Every time I try to do it though I end up with a feeling of a disjointed combination of a camera moving and zooming as two discrete things.
     
  17. luispedrofonseca

    luispedrofonseca

    Joined:
    Aug 29, 2012
    Posts:
    945
    @jwvanderbeck It should be only a matter of synchronising both events (zooming and panning). However, if you can't get the feeling you're looking for, feel free to share a sample project that replicates the issue and I'll take a look.
     
  18. Async0x42

    Async0x42

    Joined:
    Mar 3, 2015
    Posts:
    104
    Last edited: Dec 29, 2015
    luispedrofonseca likes this.
  19. luispedrofonseca

    luispedrofonseca

    Joined:
    Aug 29, 2012
    Posts:
    945
  20. AVOlight

    AVOlight

    Joined:
    Apr 15, 2014
    Posts:
    427
    can i please have scroll-wheel zoom influence (like your pointer influence extension)?

    please :)
     
    Last edited: Dec 29, 2015
  21. luispedrofonseca

    luispedrofonseca

    Joined:
    Aug 29, 2012
    Posts:
    945
    AVOlight likes this.
  22. AVOlight

    AVOlight

    Joined:
    Apr 15, 2014
    Posts:
    427
  23. ionrain

    ionrain

    Joined:
    Jan 5, 2016
    Posts:
    9
    Could somebody please help with my newbie problem? Why is the parallax plugin grayed out? And how can I make it work?
     
  24. luispedrofonseca

    luispedrofonseca

    Joined:
    Aug 29, 2012
    Posts:
    945
    @ionrain The parallax plugin is greyed out when your camera is in Perspective projection. To make it work you have to switch to Orthographic.
    This happens because the parallax effect in perspective mode does not make sense, since you get it for free.
     
    Last edited: Jan 5, 2016
  25. ionrain

    ionrain

    Joined:
    Jan 5, 2016
    Posts:
    9
  26. jmichaelmartinez

    jmichaelmartinez

    Joined:
    Jan 5, 2016
    Posts:
    1
    Hello,
    I hope your day is going lovely! Firstly, fantastic asset: its resolved all of my newbie issues. I have one question: how do I get the camera to focus on a spawned character clone in a scene? The "target" is established as the character's prefab, however, when "spawned" in a new scene, the camera does not recognize it as the target.

    This has been addressed a variety of forums (I've spent hours reading through much of them), however, after experimenting for a few days on my own, I'm at a loss.

    Again, ProCamera made everything work that I was failing to make happen on my own. Its, honestly, pretty wonderful.
    thank you for your help

    p.s. as much as this question has been asked, I wonder if might not be something to feature on the asset itself?
     
  27. flashframe

    flashframe

    Joined:
    Feb 10, 2015
    Posts:
    798
    luispedrofonseca likes this.
  28. luispedrofonseca

    luispedrofonseca

    Joined:
    Aug 29, 2012
    Posts:
    945
  29. ionrain

    ionrain

    Joined:
    Jan 5, 2016
    Posts:
    9
    Hi Luis,

    Could you help with one problem?

    When I try to build for Windows Store as Windows 10 Universal App the compiler says something like: "Assets\ProCamera2D\Core\Common\Utils\EditorPrefsX.cs(235,18): error CS1061: 'BitArray' does not contain a definition for 'CopyTo'". "Something like" because an error message has some strange symbols instead of most of the text so I looked up the error code on msdn website.
     
  30. luispedrofonseca

    luispedrofonseca

    Joined:
    Aug 29, 2012
    Posts:
    945
    @ionrain That issue should be fixed in 1.8.1 (I unfortunately have no way to test it). If you could send me your invoice number I can send you a beta.
     
  31. luispedrofonseca

    luispedrofonseca

    Joined:
    Aug 29, 2012
    Posts:
    945
    I confirmed that the WP8 fix is working so v1.8.1 was just submitted to the store with the following changes:

    - Added a Rect property to ProCamera2D core that will change its rect and the rect of parallax cameras if existent
    - Fixed build error related to EditorPrefsX classon Windows Phone 8.1
     
  32. luispedrofonseca

    luispedrofonseca

    Joined:
    Aug 29, 2012
    Posts:
    945
    While 1.8.1 is being approved, 1.9.0 is already coming along very well with two new simple extensions that have been requested a few times. Manual Zoom and Manual Pan - They work with mouse on desktop and with gestures on mobile. A sneak peek here:

    https://twitter.com/lpfonseca/status/686493654039539712
     
    Async0x42 likes this.
  33. jeffweber

    jeffweber

    Joined:
    Dec 17, 2009
    Posts:
    616
    Very useful feature.

    A question, though: When pinch zooming, will the camera zoom to the center point of the pinch rather than just the center of the screen?

    -Jeff
     
  34. luispedrofonseca

    luispedrofonseca

    Joined:
    Aug 29, 2012
    Posts:
    945
    @jeffweber You'll be able to choose between zooming to the center point of the pinch or the center of the screen.
     
    Async0x42 likes this.
  35. jeffweber

    jeffweber

    Joined:
    Dec 17, 2009
    Posts:
    616
    Is there anyway to temporarily, programmatically disable a ProCamera2D component.

    I have a diving game that uses the forward focus component. After the dive, when I hit reset, I want to temporarily disable the forward focus camera but keep the normal, default target tracking.

    Once the camera is back at the target and prior to the next dive, I want to re-enable the forward focus component.

    I've tried this:

    Code (CSharp):
    1. _forwardFocus = ProCamera2D.Instance.GetComponent<ProCamera2DForwardFocus>();
    2. _forwardFocus.enabled = false;
    which is how I'd normally disable a component, but it does not seem to work with ProCamera2D components. The component appears disabled in the inspector (no check in the checkbox) but the forward focus influence still exists as do its gizmos.

    -Jeff
     
  36. luispedrofonseca

    luispedrofonseca

    Joined:
    Aug 29, 2012
    Posts:
    945
    @jeffweber That is indeed the correct way. However, since 1.7.0, extensions no longer rely on the regular Unity update cycle for performance reasons. Therefore, they lost the ability to be turned off programmatically.
    I'll fix it ASAP and bring it on to 1.9.0. Can you please contact me directly so I can send you a beta?
     
  37. ask80me

    ask80me

    Joined:
    Sep 17, 2015
    Posts:
    43
    Hello. Discount PLEASE!!! Thank you for understanding.
     
  38. tinkergames

    tinkergames

    Joined:
    Nov 6, 2015
    Posts:
    3
    Hello @luispedrofonseca , thanks for great and consistent update for ProCamera2D! Anyway, we've got an issue on v1.8.0.
    When the character entered Trigger Boundaries there was an error popped up on the console. Here are the errors:

    Code (CSharp):
    1. transform.localPosition assign attempt for 'Main Camera' is not valid. Input localPosition is { NaN, NaN, -10.000000 }.
    2. UnityEngine.Transform:set_localPosition(Vector3)
    3. Com.LuisPedroFonseca.ProCamera2D.ProCamera2D:set_CameraPosition(Vector3) (at Assets/ProCamera2D/ProCamera2D.cs:82)
    4. Com.LuisPedroFonseca.ProCamera2D.ProCamera2DPositionAndSizeOverrider:Override() (at Assets/ProCamera2D/Core/Extensions/ProCamera2DPositionAndSizeOverrider.cs:47)
    5. Com.LuisPedroFonseca.ProCamera2D.ProCamera2DPositionAndSizeOverrider:OnPostMoveUpdate(Single) (at Assets/ProCamera2D/Core/Extensions/ProCamera2DPositionAndSizeOverrider.cs:41)
    6. Com.LuisPedroFonseca.ProCamera2D.ProCamera2D:Move(Single) (at Assets/ProCamera2D/ProCamera2D.cs:518)
    7. Com.LuisPedroFonseca.ProCamera2D.ProCamera2D:FixedUpdate() (at Assets/ProCamera2D/ProCamera2D.cs:211)
    We had some debugging and assume the variable Vector3 of `OverridePosition` on ProCamera2DPositionAndSizeOverrider.cs wasn't instantiated at first. We've tried to assign `OverridePosition` variable with current camera position. The error was gone, but it's glitchy. Sometimes the camera wasn't bounded at all, and sometimes it's move suddenly to opposite position of character.

    We've also investigated whether this error happened because instantiated Trigger Boundaries or not (because we put our level on a prefab and instantiated them). We did that because some error happened on previous version using this case. We tried the instantiated one and already placed prefabs on scene, but the errors still there.

    Hope you can get the idea of how the errors happened and can fix it thoroughly :)

    Regards
     
  39. luispedrofonseca

    luispedrofonseca

    Joined:
    Aug 29, 2012
    Posts:
    945
    @tinkergames Thanks for the bug report. Can you please send me a PM with a sample project that replicates the problem?
     
  40. tinkergames

    tinkergames

    Joined:
    Nov 6, 2015
    Posts:
    3
    @luispedrofonseca I've found the problem, it's because the 'Transition duration' on Trigger Boundary equals 0. I changed the value to 0.1 and the errors disappear :)
     
  41. luispedrofonseca

    luispedrofonseca

    Joined:
    Aug 29, 2012
    Posts:
    945
    @tinkergames Hmmm... Glad you solved it. But that shouldn't be happening any how. I'll see what's going on. Thanks!
     
  42. jeffweber

    jeffweber

    Joined:
    Dec 17, 2009
    Posts:
    616
    FYI, enable/disable of ProCamera2D components works as expected in 1.9.0. Thx!
     
  43. jeffweber

    jeffweber

    Joined:
    Dec 17, 2009
    Posts:
    616
    I noticed some strange behavior in the editor when the MainCamera is not selected.

    In my diving game, I set the camera target to a transform attached to my diver. I then dive and the camera tracks as expected.

    When I reset, I destroy my diver character, instantiate a new diver from a prefab, then re-add the transform to the cameras target list using AddTarget.

    If the Main Camera is selected in the hierarchy, everything works as expected, the camera quickly tracks to the new instance of my diver and I'm good to go.

    However, if the Main Camera is not selected in the hierarchy, the camera starts to move toward the new diver target, but then stops partway there... It gets sort of stuck at some offset. If, while it's stuck, I select the Main Camera in the hierarchy, the camera moves to the diver target as it should.

    It's as if something is not updating correctly when the Main Camera is not selected.

    Any ideas??
     
  44. luispedrofonseca

    luispedrofonseca

    Joined:
    Aug 29, 2012
    Posts:
    945
    @jeffweber That sounds weird. Having the camera selected or not should have no influence in its behaviour. Can you please share a sample project that replicates the issue?
     
  45. jeffweber

    jeffweber

    Joined:
    Dec 17, 2009
    Posts:
    616
    I actually have the exact same need as this.

    I have the 1.9 beta with the ability to do an elastic numeric boundary. It's cool, but doesn't quite give me what I want.

    The elastic boundary allows you to overshoot and then brings you back to the boundary position. The bounce back doesn't look right for my game.

    What I want is a hard boundary (camera can't go past it) like currently exists, but I also want to be able to set a secondary "influence" boundary. When the camera is between the influence boundary and the hard boundary, it's motion in the direction of the hard boundary is negated by an amount directly proportional to the distance of the camera from the hard boundary. The closer the camera gets to the hard boundary the more the movement is negated.

    Not sure the details are correct, but hopefully you follow what I mean.

    Example scenario:

    Diver jumps off cliff.

    When diver approaches water, camera's vertical motion slows and eventually stops at some pre-determined position to give the player a good view of the entry into the water.

    The current numeric boundary stops the camera too quickly and it's a bit jarring to the player.

    -Jeff
     
  46. jeffweber

    jeffweber

    Joined:
    Dec 17, 2009
    Posts:
    616
    I am using Unity 5.4 beta 1 so maybe that's causing the issue. I'll hold off until 5.4 stabilizes a bit and if it still happens I'll try to create a simple project that shows the issue.
     
  47. luispedrofonseca

    luispedrofonseca

    Joined:
    Aug 29, 2012
    Posts:
    945
    @jeffweber I'll give some thought about that soft boundary you described. It may be harder to implement than it sounds. I'll keep you posted.
     
    Async0x42 likes this.
  48. Async0x42

    Async0x42

    Joined:
    Mar 3, 2015
    Posts:
    104
    +1 for the soft boundary, I think that feels more natural than bouncing back after over extending (especially since I think it would be a common case for people to not have graphics beyond certain boundaries in 2D)

    Thanks for the great work on PC2D by the way, lately I haven't been using Unity often, but I check up on the asset daily. It's easily more often updated with fixes and new features, than any other asset I own. Never regretted paying full price for this!
     
    ikazrima and luispedrofonseca like this.
  49. luispedrofonseca

    luispedrofonseca

    Joined:
    Aug 29, 2012
    Posts:
    945
    So for 1.9.0, I decided to merge the new ManualZoom and ManualPan extensions into one and call it PanAndZoom.
    It allows to manually zoom (either with mouse or pinch gesture), to center of the camera or center of the input position.
    It also allows to manually pan the camera by dragging the 'world' or by moving the mouse to the edges of the screen.
    As usual, there are a bunch of configurable parameters and the extension is fully compatible with all the others.

    Here's a screenshot of the extension editor:

    camera_pan_and_zoom.png

    If you'd like to get access to a beta that contains this new extension please get in touch.
     
    flashframe, Async0x42 and jeffweber like this.
  50. Async0x42

    Async0x42

    Joined:
    Mar 3, 2015
    Posts:
    104
    Some improvements I thought of for the Shake component that would be nice:
    1. When selecting a preset that has already been created, change the values in the Shake script editor view, so we can see what the preset was set to. (There's no way to know what the values in a preset are). Then users can change the values, click 'Apply', and update the preset.
    2. 'Apply' should be greyed out, if nothing has been changed vs the stored preset (the preset name, or any variables in the editor component)
     
    luispedrofonseca likes this.