Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Master Camera: Scroll/Zoom, Strafe, FPS-3PS Toggling, Minimal/No Clipping and More

Discussion in 'Assets and Asset Store' started by tzvier, Dec 8, 2011.

  1. unityasoft

    unityasoft

    Joined:
    Oct 28, 2011
    Posts:
    263
    Worked like a charm, I previously tried adjusting the "-" object... I see where it went wrong.

    Thank you tzvier!
     
  2. gdavid

    gdavid

    Joined:
    Apr 8, 2012
    Posts:
    6
    I love your camera system. Works so easily.
    My question is, I would like to have a camera which works similar to Costume Quest. It is like the mouse horizonal but it does not follow from behind. It follows to the side. Like a 3d side scroller I guess you could say.
     
  3. outtoplay

    outtoplay

    Joined:
    Apr 29, 2009
    Posts:
    741
    AH! Love Costume Quest.. great little game (though the repetition of the fights matches gets old.)

    My Question is could this camera system be configured to a 2d side scroller. A lil softness on the vertical axis, that sweet physics feels. And perhaps when the character jumps or my case, flies, the camera pulls back to reveal more of the scene. (sort of like Tiny Wing between Islands.)

    Having this Camera system for 2d games would be terrific.


    thanks,
    B.
     
  4. angel_m

    angel_m

    Joined:
    Nov 4, 2005
    Posts:
    1,160
    Very good work. My only complaint is I can't reset the camera strafe (back to center).
     
  5. john-essy

    john-essy

    Joined:
    Apr 17, 2011
    Posts:
    464
    I am thinking about buying this but... I want to know if it could support 3rd person shooters as in... something like ratchet and clank when you move around you can rotate the camera and so forth but if your weapon is equipped then it would kind off switch to a different kind of camera for aiming of the weapon.

    If this is possible then i am buying it.
     
  6. tzvier

    tzvier

    Joined:
    May 20, 2010
    Posts:
    355
    Thanks for the comments and questions! Sorry for the delay in replies. I'm in the process of moving back to the US from S. Korea, and my internet access is currently shakey at best. I tried to respond yesterday, but it apparently didn't go through.

    @gdavid outtoplay : Yes 2D side scroller is completely possible. If you lock the min/max rotation angles for both the horizontal and vertical axis in the main script, (for example setting the horizontal min max to 90, and the vertical min max to 0) this will lock the camera in a relative stationary position and only look at the character from the same side. You should then remap the inputs of "w" to jump, and "s" to crouch, or whatever. Basically disabling the ability to move the character away or toward the camera (plane / box colliders to hold the character in place would probably be a good idea too.)

    As far as zooming in/out while jumping / flying: You could write a simple script that alters the "Preferred Distance" variable in the main script, and make sure the MCScroll script is attached with "Enable Wheel Scrolling" Disabled.

    @angle_m : Setting the camera strafe to center can be done in a couple ways. The first and easiest is to just set the strafe speed and limit to the same value. For instance if you set the speed to 0.5 and the limit to 0.5, that will allow for only 3 possible strafe positions, left, center and right, the lower you make the speed, the more possible strafe position, the harder it can be to manually move it back to center.

    If you would like to allow more subtle control over the camera strafing, and still be able to snap it back to center, in the MCStrafe script on line 16 there is a private variable named strafeLocation which is a float. You can just make that not private (public), and put together a small script that sets that variable to 0 on key press, or whatever trigger you want to set it to center.

    @ john essy: 3PS is one of the demo scenes that comes with the project files. Also, as you can see in the demo, it is possible to switch between camera types at runtime, allowing a great variety of options to view your games action.

    I hope that keeps you progressing in your projects. Please let me know if you have any more questions or concerns, but again, at the moment my access to internet is currently not the best. I am working to resolve this issue.
     
    Last edited: Sep 5, 2012
  7. cygnusprojects

    cygnusprojects

    Joined:
    Mar 13, 2011
    Posts:
    766
    Was this asset tested with Unity 4 already? The camera is clipping through objects even with the Collision Layer Mask setup correctly.

    Edit: After applying the MC3PPlatformer Preset the collision worked but the camera is jumping up and down and at the same time the LocationAdjustment is getting lower and lower until it disappears off scene together with the camera.

    Am I missing something?

    Edit 2: The camera has jerking movement because my player has a rigid body attached. If I remove the rigid body then the camera behaves as adverticed. Any idea how I can keep my rigidbody attached to the player without having the camera making jerky movement?
     
    Last edited: Sep 27, 2012
  8. tzvier

    tzvier

    Joined:
    May 20, 2010
    Posts:
    355
    cygnus, Did you just add a rigidbody to the normal character controller? Doing that, I get the behavior that you've described. If the rigidbody's gravity off, the behavior stops. For some reason the rigidbody's gravity is interfering with where the camera thinks the "Player" location.y is. . .hmm.

    Do you need gravity on? I suspect it has something to do with the character controller managing the gravity of the character for jumping etc, combined with the gravity of the rigidbody.
     
    Last edited: Sep 28, 2012
  9. cygnusprojects

    cygnusprojects

    Joined:
    Mar 13, 2011
    Posts:
    766
    Hi tzvier,

    Yes I'm having a rigid body attached to my character (with gravity checkbox checked) because I want to have full collision detection and according to the docs this can only be achieved by using rigid bodies (see collision matrix on http://docs.unity3d.com/Documentation/Manual/Physics.html)

    It is disappointing you can't use gravity on the main character though.
     
  10. tzvier

    tzvier

    Joined:
    May 20, 2010
    Posts:
    355
    I have found a solution. I will be uploading a new version shortly. In the meantime, if you want to get going while the package is waiting to be accepted you can just open the MasterCamera.js script, and go to the Update function around line 100. Take the first command in the Update function that says:

    Code (csharp):
    1.  
    2. transform.position = Vector3.Lerp(transform.position, player.transform.position, Time.deltaTime * smooth.Location);
    3.  
    and create a LateUpdate function, and put that code in it, so you end up with:
    Code (csharp):
    1.  
    2.  
    3. function LateUpdate (){
    4.     // Follow the Character position with smoothing.
    5.     transform.position = Vector3.Lerp(transform.position, player.transform.position, Time.deltaTime * smooth.Location);
    6. }
    7.  
    8. function Update () {
    9. //
    10. //Determine Camera Rotation
    11. //
    12.  
    13.  
    And that should allow you to have your character controller + rigidbody w/ gravity. Let me know if that works out for you! Also if you have any other questions, I'm here.
     
  11. cygnusprojects

    cygnusprojects

    Joined:
    Mar 13, 2011
    Posts:
    766
    Thank you for the quick reply and great support! I'll test it asap in the meantime I found another issue (sorry, I'm testing thouroughly ;-)):
    When you have a character that is customizable be setting renderer on or off depending on the actual character state (fi in level 1 your character has no cape only from level 5 onwards) and you use the MeshHiding functionality once the camera turned off the renderers and you are moving the camera away from the character so it comes visible again all renderers are turned on (so my character has a cape on level 1).
    Hope this comment is somewhat clear on what I mean otherwise please let me know.

    Edit: Fix for the character controller + rigidbody with gravity is working great. Thanks!
     
    Last edited: Sep 28, 2012
  12. tzvier

    tzvier

    Joined:
    May 20, 2010
    Posts:
    355
    Great, glad to hear that the camera isn't all jumpy anymore.

    As far as the mesh hiding, could you disable the cape game object until level 5? Other than that, I think you may just have to turn MasterCamera's MeshHiding off, and write your own small script to handle which parts you want on and off. You could still access the PrefferedDistance variable in the main script to determine the position of the camera.
     
  13. Hamesh81

    Hamesh81

    Joined:
    Mar 9, 2012
    Posts:
    405
    Hi tzvier, I have a feature request but I'm not sure if it's too difficult to implement. I really like the MCButtonLook and how it can be set to either return on click or not. In my setup I have the left mouse button set with an MCButtonLook to rotate the camera around. For the right mouse button I would also like to have something similar. When I click the right mouse button once I would like to enter a MouseLook free rotation mode without the need to hold down the mouse button, and then if I click again while in this mode I would like to exit and return the fixed camera rotation/position back to the way it was before the first click. Does this make sense?
     
  14. cygnusprojects

    cygnusprojects

    Joined:
    Mar 13, 2011
    Posts:
    766
    Hi tzvier,

    I implemented a check on enabled renderers within the if(meshHiding.enableMeshHiding){ of the MCScroll addon myself. I create a list of the enabled renderers and only update those when dealing with enabling/disabling the meshes. Seems to work perfectly.
     
  15. tzvier

    tzvier

    Joined:
    May 20, 2010
    Posts:
    355
    Awesome cygnus, glad to hear it.

    Hamesh, that shouldn't be too difficult. Let me see what I can come up with.
     
  16. Hamesh81

    Hamesh81

    Joined:
    Mar 9, 2012
    Posts:
    405
    Look forward to it :)
     
  17. tzvier

    tzvier

    Joined:
    May 20, 2010
    Posts:
    355
    New version submitted.

    2.5.7

    - Fixed character controller + rigidbody issues.
    - Added ClickToToggle option for MCButtonLook. (Hamesh, let me know if this works for you)
     
  18. Hamesh81

    Hamesh81

    Joined:
    Mar 9, 2012
    Posts:
    405
    Thanks a lot! Will test it out when it hits the asset store:)
     
  19. tzvier

    tzvier

    Joined:
    May 20, 2010
    Posts:
    355
    I apologize about the delay with this update. The package manager is having some issues with the version number. I'm am trying to get this resolved asap.
     
  20. cygnusprojects

    cygnusprojects

    Joined:
    Mar 13, 2011
    Posts:
    766
    Hi Tzvier,

    I'm having a feature request:

    Sometime it happens when the camera is in Follow mode it is not positioned behind the player when somewhere within the game you use the Horizontal axis for character movement. Would it be possible to provide an addon for the system so the camera is always rotating back to the players back?
     
  21. tzvier

    tzvier

    Joined:
    May 20, 2010
    Posts:
    355
    Cygnus, I have added that feature and submitted it to the Asset Store. v2.5.8

    The feature is a new Camera Rotation Mode called "FollowBehind" which is accessible from the drop down in the main MasterCamera script.
     
    Last edited: Oct 11, 2012
  22. cygnusprojects

    cygnusprojects

    Joined:
    Mar 13, 2011
    Posts:
    766
    tzvier, that was quick! Thanks for the great support, awaiting for Unity to update their asset store.
     
    Last edited: Oct 12, 2012
  23. TopThreat

    TopThreat

    Joined:
    Aug 7, 2012
    Posts:
    136
    When I looked at updating from the asset store the option was not available. Are there two versions of this on the store now? One is asking me to purchase the asset again and the other is offering me to import a previous version.

    Thanks!

    Lee
     
  24. tzvier

    tzvier

    Joined:
    May 20, 2010
    Posts:
    355
    Yes, I'm sorry about that. Update 2.5.7 got uploaded as a separate asset with the name "Master Camera" instead of "MasterCamera" as my Publisher Administration has been having some issues. Supposedly update 2.5.8 has been applied to the appropriate "MasterCamera" asset ( the one that people have purchased / the one with all the reviews.) However, when I log in, I do not see 2.5.8 anywhere, so I'm looking into this...

    I sincerely apologize for the confusion and I hope this all resolved soon.
     
  25. Hamesh81

    Hamesh81

    Joined:
    Mar 9, 2012
    Posts:
    405
    Hi tzvier, just letting you know I have tested version 2.5.8 with the requested functionality. It's brilliant, exactly what I wanted. Thank you so much and keep up the awesome work :)
     
  26. Hamesh81

    Hamesh81

    Joined:
    Mar 9, 2012
    Posts:
    405
    Hi Tzvier, I am trying to create a 3D side scroller camera but I'm having trouble keeping the camera 90 degrees to the side of the character. I need my character to be able to walk into the foreground and background but maintain a side on view, any suggestions as to how to do this? I thought maybe if there were a setting in the main Master Camera script like "FollowBehind", but instead "FollowLeft" or "FollowRight".

    Also, I am getting some strange twitching behaviour with my character's animations. If I use a normal camera the animations are smooth and fine, but if I use a Master Camera Rig, all the animations are really twitchy even though the camera itself rotates smoothly. Any idea why this could be? The character uses a rigidbody setup if that helps (no character controller), and I have updated to the latest 2.5.8 version.
     
    Last edited: Nov 12, 2012
  27. tzvier

    tzvier

    Joined:
    May 20, 2010
    Posts:
    355
    Hamesh, in order to get a side scroller camera, set the follow mode to "Follow" and set the min / max horizontal settings to the same value. For example set them both to 90, or whatever is appropriate for how you've set up your scene. That will keep the camera locked facing that direction in world space.

    As far as the animations, the only thing I can really think of is maybe the rigidbody is colliding with the rig somewhere? With out seeing the actual project in this instance, it may be a little difficult to diagnose. Feel free to PM me and we can set up a time to look into it through teamviewer or something.
     
  28. Hamesh81

    Hamesh81

    Joined:
    Mar 9, 2012
    Posts:
    405
    Hi Tzvier, I've managed to figure everything out. The side scroller works as you suggested above and after disabling the character's Mouse X movement code there is no more twitching as well. Thanks alot
     
    Last edited: Nov 14, 2012
  29. Hamesh81

    Hamesh81

    Joined:
    Mar 9, 2012
    Posts:
    405
    I have another question if I may ;)
    I setup up a default camera into the position and rotation that I need, and now I am trying to get a Master Camera rig to match this. I have tried copying the default camera's position/rotation from the inspector into the location adjustment of the rig, but it isn't matching at all. Both are not parented to anything. How could I do this?
     
  30. tzvier

    tzvier

    Joined:
    May 20, 2010
    Posts:
    355
    When you change the position and rotation of the "Location Adjustment" you are changing the local values. Whereas when you are changing the default camera values (as this camera is not parented to anything) you are changing world values.

    The things that will get your Master Camera rig to match the default camera in this situation are the following:

    -Location Adjust local position Y (change in the "transform" section of the inspector, or just drag it up and down)
    -MasterCamera.js > Horizontal > Rotation Min/Max
    -MasterCamera.js > Vertical > Rotation Min/Max
    -MasterCamera.js > Preferred Distance

    So, I would suggest:
    1. Drop a box (or any visual aid) down where your default camera is. Make sure it has no collider.
    2. Put the MasterCamera rig into MouseHorizontalAndVertical mode.
    3. Select the MC.RotationPoint in the hierarchy so you can see it's transform values.
    4. Use the mouse to move the camera so that it's in line with your visual aid.
    5. Copy the MC.RotationPoint local rotation X value to the MasterCamera.js > Vertical > Rotation Min/Max.
    6. Copy the MC.RotationPoint local rotation Y value to the MasterCamera.js > Horizontal > Rotation Min/Max.
    7. If the camera is not the same distance from the character, adjust the MasterCamera.js > Preferred Distance accordingly.

    Now this should get you really close. If the angle the camera is facing is not satisfactory at this point, adjust the Location Adjust local position Y. After that you'll have to repeat steps 3-6.

    Finally set your follow mode back to "Follow" and you should be good to go.
     
  31. ThunderbirdX11

    ThunderbirdX11

    Joined:
    Nov 18, 2012
    Posts:
    2
    Hello tzvier,

    thanks for such an great Asset :) I almost figured out the settings that are important for my game except for terrain/building collision.

    I ticked the "Enable Camera Collision Box" and assigned the Camera-Rig and the Player to the Physics Layer "MC" and I made sure that the Camera hits every Objects on every Physics Layer except the "Player" and the "Ignore Raycasts".

    My Terrain is set to "Terrain"-Layer
    My Houses are on the "Default"-Layer
    Player and Rig are on the "MC"-Layer and both tagged as Player.


    Pictures can describe more than thousand words can:


    What am I missing?
     

    Attached Files:

  32. tzvier

    tzvier

    Joined:
    May 20, 2010
    Posts:
    355
    Thunderbird, Are you using Unity4?

    What happens to the "Collision Layer Mask" when you hit Play?

    Do you have any objects that have the MCLOSFadeOthers.js script attached?
     
    Last edited: Nov 19, 2012
  33. ThunderbirdX11

    ThunderbirdX11

    Joined:
    Nov 18, 2012
    Posts:
    2
    Hi tzvier,

    I'm using Unity 3.5.6.

    The Collision Layer Mask stays as it is when I hit Play

    No there are no Objects with the MCLOSF Script attached. I just attached Mastercamera und MCScroll to the Rig.

    Unfortunately, switching to FPS (with MCScroll) also doesn't work.

    My Character has a normal Character Controller attached to it. Do I need the third person controller for the scripts to work?
     
  34. tzvier

    tzvier

    Joined:
    May 20, 2010
    Posts:
    355
    I am sent you a PM. We'll have to set a time to take a look at this together over teamviewer, skype or something.
     
  35. Hamesh81

    Hamesh81

    Joined:
    Mar 9, 2012
    Posts:
    405
    @ThuderbirdX11, I had a similar problem before and it turned out to be the mc scroll limit inner and limit outer. In my case the camera kept clipping through things because the limit values weren't far apart enough so the camera didn't have enough "room to move" to avoid the obstacles. I ended up making another two separate float variables to control the camera collision scrolling and mouse wheel scrolling separately. Not sure if this is your case or not, just thought I'd share ;)

    @tzvier, Thanks a lot for your advice with the cam positioning, I ended up using the orthographic views in the scene view and the camera icons to align the two positions to roughly the same spot. It looks great now.
    I have a script suggestion if I may to the "Return on Click" functionality of the MCButtonLook. Would it be possible to add a speed variable which controls how fast the camera returns to the original position after the click? I would like to be able to control the return transition between a gradual one and the instant one it is now. I have tried implementing this myself but so far I haven't been very successful with it.
     
  36. tzvier

    tzvier

    Joined:
    May 20, 2010
    Posts:
    355
    Thanks for the notes Hamesh. I was able to get together with Thunderbird over teamviewer and we got everything straightened out.

    Glad to hear you got your camera set up. As far as adding a speed variable, that may be a little tricky. I'm not making any promises, but I'll see what I can do.
     
  37. Hamesh81

    Hamesh81

    Joined:
    Mar 9, 2012
    Posts:
    405
    Ok sure no problems. If it helps I have used Mathf.MoveTowardsAngle before to smoothly rotate to a specific angle at a certain speed, I'm trying to use that here as well but haven't had much success yet. Please let me know how you go
     
  38. Hamesh81

    Hamesh81

    Joined:
    Mar 9, 2012
    Posts:
    405
    Hi again tzvier, I have another question about the use of ragdolls with the master camera. I have tried all of the different rotation modes, but for some reason whenever my character enters into ragdoll mode the entire camera rig jumps higher on the y axis by about half a meter. When I exit ragdoll mode the rig returns to the proper position as before. Any idea as to what could be responsible for this?

    I am also adding a code snippet regarding the speed variable for the "return on click" I mentioned before. It isn't quite working at the moment but I thought maybe could it be a starting point? If this gets working I think it would be a great addition for everyone to use :) :

    Code (csharp):
    1. if(returnToOnClick){
    2.    
    3.         if(clickToToggle  toggled){
    4.             if(Input.GetButtonDown(inputButton)){      
    5.                 //mc.rotationObject.transform.localEulerAngles.y = hReturn;
    6.                 //mc.rotationObject.transform.localEulerAngles.x = vReturn;
    7.                
    8.                 var angleH = Mathf.MoveTowardsAngle(
    9.                 mc.rotationObject.transform.eulerAngles.y, hReturn, cameraResetSpeed * Time.deltaTime);
    10.                 mc.rotationObject.transform.eulerAngles = Vector3(0, angleH, 0);
    11.                
    12.                 var angleV = Mathf.MoveTowardsAngle(
    13.                 mc.rotationObject.transform.eulerAngles.x, vReturn, cameraResetSpeed * Time.deltaTime);
    14.                 mc.rotationObject.transform.eulerAngles = Vector3(angleV, 0, 0);   
    15.             }
    16.         }
    17.        
    18.         if(Input.GetButtonUp(inputButton)){    
    19.             //mc.rotationObject.transform.localEulerAngles.y = hReturn;
    20.             //mc.rotationObject.transform.localEulerAngles.x = vReturn;
    21.            
    22.             var angleH2 = Mathf.MoveTowardsAngle(
    23.             mc.rotationObject.transform.eulerAngles.y, hReturn, cameraResetSpeed * Time.deltaTime);
    24.             mc.rotationObject.transform.eulerAngles = Vector3(0, angleH2, 0);
    25.                
    26.             var angleV2 = Mathf.MoveTowardsAngle(
    27.             mc.rotationObject.transform.eulerAngles.x, vReturn, cameraResetSpeed * Time.deltaTime);
    28.             mc.rotationObject.transform.eulerAngles = Vector3(angleV2, 0, 0);
    29.         }
    30.     }
     
  39. tzvier

    tzvier

    Joined:
    May 20, 2010
    Posts:
    355
    Return on click speed has been implemented and is in version 2.5.9 which just got accepted.

    With regard to the Ragdoll: Is it because the ragdoll origin is higher than the character's origin?
     
  40. Hamesh81

    Hamesh81

    Joined:
    Mar 9, 2012
    Posts:
    405
    Omg that's great! Can't wait to test it out :) Thank you so much and hope it wasn't too much trouble.
    How can I tell what the ragdoll origin is? My ragdoll and character are actually the same prefab. The character simply has rigidbody components on each bone and some character joints also; so to trigger a ragdoll Animation is turned off and rigibodies turned on. Wouldn't that mean that there origins are the same, or is there something I can check to make sure?
     
  41. tzvier

    tzvier

    Joined:
    May 20, 2010
    Posts:
    355
    I'll PM you.
     
  42. Hamesh81

    Hamesh81

    Joined:
    Mar 9, 2012
    Posts:
    405
    Ok I figured out the culprit!
    Since I had parented the Master Camera rig to my character, with all the visualizations and other bits it made the top level gameobject's origin different to what it was before. I had to change the Master Camera to follow the root bone and NOT the top level GO. Thanks for helping me figure this out.

    I also have another question. I am trying to use another Master Camera to smoothly follow a particular bone in my character's hierarchy, in this case the neck bone. I would like to have an over the shoulder view which smoothly follows the character's neck rotation while they are animating. So a natural "bobbing" like effect would happen as they walk/run for example, or while they shift their weight in idle the camera will also move with them. I have tried parenting the camera rig to the neck bone but this creates too much nauseating movement. I've also tried setting the "Player" variable to the neck, but the camera does not rotate with the player's neck bone, only with the entire gameobject. Any ideas how I could achieve this?
     
    Last edited: Dec 7, 2012
  43. merlin981

    merlin981

    Joined:
    Apr 16, 2012
    Posts:
    305
    Any plans to make this available for Unity 3.5? Currently it requires 4.0
     
  44. tzvier

    tzvier

    Joined:
    May 20, 2010
    Posts:
    355
    @merlin: The package that is available from here. is pre 4.0.

    @Hamesh, you could try playing with the Smooth > Location speed with the "Character" set to the neck bone. Beyond that, it may require a custom script.
     
  45. merlin981

    merlin981

    Joined:
    Apr 16, 2012
    Posts:
    305
     
  46. PeterB

    PeterB

    Joined:
    Nov 3, 2010
    Posts:
    366
    Just purchased this package. However, the Asset Store seems still to think it's not purchased, despite sending receipts proving it is. Doesn't matter if I log out and in again. Does anyone know how to beat the Asset Store into submission? The amount of aggro this produces is substantial.
     
  47. tzvier

    tzvier

    Joined:
    May 20, 2010
    Posts:
    355
    PeterB, did you purchase the package that is "Master Camera" not the one that is "MasterCamera"? The one with the space, was supposed to have been removed from the asset store, but apparently not. . . I had some issues with submission process when I built a new computer, accessing the my accounts and submissions properly. This was suppose to have been taken care of. I apologize for the inconvenience. Maybe return one for the other, if you can't get Unity to take care of it?
     
  48. Zozo2099

    Zozo2099

    Joined:
    Jul 15, 2012
    Posts:
    478
    Please can I know if it is compatible with Unity 4?
     
  49. tzvier

    tzvier

    Joined:
    May 20, 2010
    Posts:
    355
    Yes, MasterCamera available on the Asset Store is compatible with Unity4.
     
  50. rezilausiv

    rezilausiv

    Joined:
    Nov 18, 2010
    Posts:
    126
    Hi

    We tested MasterCamera with Unity 4 (MAC OSX 10.6.8).

    Unfortunately with the 3PSDemo scene it is not blending out the walls between the camera and the character any more.
    But that is the main deal of MasterCamera.