Search Unity

  1. Unity 2019.1 is now released.
    Dismiss Notice

Camera Controller Release

Discussion in 'Assets and Asset Store' started by Tryz, Dec 21, 2013.

  1. Tryz

    Tryz

    Joined:
    Apr 22, 2013
    Posts:
    3,173
    Thanks @FenixOfGreen ,

    There's nothing that will spring the pitch back automatically, but you can add your own code to do it.

    In both cases, you can use the SetYawPitch() function on the motor.

    You can write code something like this:
    Code (CSharp):
    1. CameraController lCameraRig = gameObject.GetComponent();
    2. YawPitchMotor lYawPitchMotor = lCameraRig.ActiveMotor as YawPitchMotor;
    3. if (lYawPitchMotor != null)
    4. {
    5.     lYawPitchMotor.SetYawPitch(0f, 0f);
    6. }
    There's a section in the User's Guide where I talk a little bit more about the code and give some small examples:
    http://www.ootii.com/Unity/CameraController/CCUsersGuide.pdf

    That should help.
     
  2. limpin_jezus

    limpin_jezus

    Joined:
    Nov 20, 2015
    Posts:
    13
    Has anyone modified a motor to orbit an object like the 3rd person motor, but also have vertical camera movement? I need that rig and my attempts at creating a custom motor so far are not working so well. I've been trying to modify the 3rd person motors and something is springing the camera back to the original vertical position every frame. I'll continue banging on it, but if anyone has done this previously I'd rather not reinvent the wheel. :)
     
  3. Tryz

    Tryz

    Joined:
    Apr 22, 2013
    Posts:
    3,173
    I'm not sure what you mean by "also have vertical camera movement"?

    The 3rd person motors primarily use 3 values: yaw, pitch, and distance. Think of the center of the sphere being the anchor + anchor offset. The yaw and pitch determine the direction from the center. Then, the distance is the distance the camera is from the center along that direction. The camera basically stays on the surface of a sphere that surrounds the character.

    So, I'm not sure what vertical camera movement would be (other than pitch). If you can explain that more, I might be able to help.
     
  4. limpin_jezus

    limpin_jezus

    Joined:
    Nov 20, 2015
    Posts:
    13
    Vertical movement without a pitched angle. Just simple up/down with a level camera. As an example, with the third person motor with zoom enabled, you can only zoom in on a fixed point of the viewed object (the center). I'd like to be able to move the camera up and down and zoom at that 'level' without an angle. In this view here, if I pitch up and zoom, it will always only zoom in on the stomach, no matter the pitch angle. I need to be able to zoom in on any part of the model.
    upload_2018-5-22_23-58-56.png

    upload_2018-5-22_23-59-24.png
     
  5. Tryz

    Tryz

    Joined:
    Apr 22, 2013
    Posts:
    3,173
    Ah... I see.

    What you really want to do is modify the anchor position and/or the distance.

    As I mentioned, the camera is going to look at the center or focus point; that's the anchor + anchor offset. So, you want to lift the transform that is the anchor or change the anchor offset value.

    To fit with your pictures, I'd also change the distance value at the same time.


    The camera motor is just looking where you tell it. So, in my picture, the anchor is the same, but I shortened the offset (y-value) and shortened the distance.

    With that the camera does "move vertically" because the focus point (anchor + anchor offset) moved vertically.
     
  6. limpin_jezus

    limpin_jezus

    Joined:
    Nov 20, 2015
    Posts:
    13
    Perfect! Thanks for the pointers. Now it works like a charm!! I was able to adjust the Offset, in RigLateUpdate, modifying the 3rd Person Fixed motor as such:

    Code (CSharp):
    1. if (_UpActionAlias.Length > 0 && RigController.InputSource.IsPressed(_UpActionAlias))
    2.             {
    3.                 RigController.AnchorOffset = RigController.AnchorOffset + (Vector3.up * (_VerticalSpeed * rDeltaTime));
    4.             }
    5.  
    6.             if (_DownActionAlias.Length > 0 && RigController.InputSource.IsPressed(_DownActionAlias))
    7.             {
    8.                 RigController.AnchorOffset = RigController.AnchorOffset + (Vector3.down * (_VerticalSpeed * rDeltaTime));
    9.             }
    Now to add some clamping to keep the object in focus...
     
    Tryz and hopeful like this.
  7. FenixOfGreen

    FenixOfGreen

    Joined:
    Oct 2, 2017
    Posts:
    20
    Thanks for the help, but ill be honest, im completely lost. I went through the Documentation on code and through the code it self but i just cant seam to follow it. Maybe im stupid and missing something but i have no idea where to put the code you suggested.

    btw im using the 3rd person follow camera if that makes a difference
     
  8. Tryz

    Tryz

    Joined:
    Apr 22, 2013
    Posts:
    3,173
    You said you wanted to have the pitch spring back to the default when you release the mouse (or some other event).

    So, you put the code where you would respond to the release of the mouse. I don't know your game code, but I'm assuming you have a Monobehaviour somewhere that has code watching input. You'd put the code there in response to the release of the mouse.
     
  9. FenixOfGreen

    FenixOfGreen

    Joined:
    Oct 2, 2017
    Posts:
    20
    Okie Dokie, Thanks for the help. I put the code you suggested into the CameraControler. Will it work? Beats me, again im kinda clueless by nature unfortunately. The only problem is the red squiggly under GetComponent. Any idea on how to fix it?
     

    Attached Files:

  10. Tryz

    Tryz

    Joined:
    Apr 22, 2013
    Posts:
    3,173
    No. You don't want to modify my code.

    You have to create your own component (called a Monobehaviour in Unity).

    Unfortunately, the feature you want isn't something the Camera Controller does. The code I provided will do it, but it sounds like you'll need some Unity coding knowledge.

    You may want to check out some of Unity's videos on programming. That will explain what a Monobehaviour is and how you can customize Unity's gameplay.
     
  11. FenixOfGreen

    FenixOfGreen

    Joined:
    Oct 2, 2017
    Posts:
    20
    i do know unity code, im just crap at it lol. ill figure it out eventually. Thank you for the help
     
    Tryz likes this.
  12. jovino

    jovino

    Joined:
    Jun 5, 2013
    Posts:
    19
    Hello Tryz

    I am a happy new customer, used to work with **other developer** frameworks, your modular architecture and composition vs conditional code (motors, for example) is really refreshing, thank you for the great tools.

    I am playing now with a small fps project, and, while I'm at it, an idea has come to my mind: how can i get a weapon camera with Ooti assets so i can drop all this mess too? :)

    I know your packs are third person focused, but I think a weapon camera with some procedural motion it's not a big problem for you, maybe as a new pack? What do you think about it?
     
  13. Tryz

    Tryz

    Joined:
    Apr 22, 2013
    Posts:
    3,173
    Hey @jovino , Thanks! :)

    What do you mean by a 'weapon camera'?

    With the camera motors included, you should be able to get most of the views you want... or pretty close. Describe what you mean a bit more and maybe I can help.
     
    jovino likes this.
  14. jovino

    jovino

    Joined:
    Jun 5, 2013
    Posts:
    19
    This is what I mean by "weapon camera"



    Usually rendered in a separate layer together with the main camera, so you can get a different FOV to get that "modern fps" look
     
  15. Tryz

    Tryz

    Joined:
    Apr 22, 2013
    Posts:
    3,173
    Got it.

    Usually this is a second camera put on a different layer. The world is rendered by one camera and ignores the gun while the other camera draws on top of that and ignores the world. This way if the character is against a wall, the gun doesn't get clipped by the wall.

    That's not something the CC would do since you would do that by setting the multiple cameras and layers they render. The CC would manage the position and rotation. You'd just add two cameras to the setup vs. the normal 1 and it should all work now.


    I believe I talk about this in my Shooter Motion Pack docs. I'm on vacation right now and don't have the link handy.
     
  16. jovino

    jovino

    Joined:
    Jun 5, 2013
    Posts:
    19
    Oh, come on, enjoy your vacation and stop working now!

    I found the link already, https://ootiigames.com/?p=905.
     
    hopeful likes this.
  17. silentneedle

    silentneedle

    Joined:
    Mar 14, 2013
    Posts:
    280
    Is there a way to setup the controller to act like a typical MMO camera? The 3rd person (fixed) is almost what I'm looking for, except that the camera doesn't follow the character rotation (q/e) and the scroll wheel zooms instead changing the camera distance.
     
  18. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    2,160
    So just opened up the third person view demo and pitch/yaw speed are having zero effect.

    Also, I can't have the camera as a child of the controller. Is there built in support for simply telling your controller which camera to control?
     
  19. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    2,160
    Ok pitch/yaw speed work fine. It's that the active motor isn't the selected motor by default, so I wasn't modifying the correct one.
     
    Tryz likes this.
  20. halley

    halley

    Joined:
    Aug 26, 2013
    Posts:
    686
    Just downloaded the asset and loaded it into a clean 2018.1 project on MacOS. I must have the worst luck because this is the second asset in a row which does not do what the demo says it should do, out of the box.

    The 3rd-person demo says on the screen:

    WASD = Move character (this works)
    QE = Rotate character (this works)
    LMB = Orbit character (this works, a bit slow, probably adjustable)
    RMB = Rotate camera and character (this behaves identically to LMB, moving camera only)

    The PDF suggests MMB also does "Aim" but it does nothing.

    If I move the character, the camera creeps along very slowly until it is eventually behind the character, like a truck hauling a trailer. But if I stop moving the character, there is no spring or momentum to the camera to bring it behind the character at all. The RMB does not rotate the character at all. I found the Jones object has a "Rotate to Input" feature which if enabled will SNAP the orientation of the character to wherever the camera was set independently on the next application of WASD, a very clunky feel.

    The "free flight" demo does nothing, for keyboard nor mouse. This error is the culprit:

    ArgumentException: Input Axis MXRightStickX is not setup. ...
    com.ootii.Input.UnityInputSource.get_IsViewingActivated () (at Assets/ootii/Framework_v1/Code/Input/UnityInputSource.cs:195)

    And the "showcase" demo should be renamed "spline" as that's all it's showing off. The spline demo transitions to third person.

    So what am I missing?
     
    Last edited: Jul 1, 2018
  21. MrG

    MrG

    Joined:
    Oct 6, 2012
    Posts:
    294
    After reading through the documentation, I was hoping for a more advanced occlusion avoidance mechanism for the 3rd person camera. It seems all you're doing is a single spherecast to target and yanking the camera forward if that one thin line is blocked. Perhaps you could consider reversing this to raycasting from the target to 4-6 points around the near clip plane and orbiting the camera away from obstructions as they approach the view frustum before they actually obstruct the camera's view of the target.

    In simplest form, imagine the four points of a plane that is aligned with the near clip plane and 3X larger. If the rays to the left corners hit an obstruction but the rays to the right corners do not, orbit the camera to the right, and vice versa. Same idea for ceilings and floors where you'd orbit down or up respectively instead of moving the camera closer. If 3 or more points are obstructed, then move the camera forward just to the farthest point from target (longest ray distance) where orbiting would be possible because you've cleared one or two of the obstructed rays.

    Of course you still have to remember where the camera was so you can lerp it back when the obstruction is gone unless the player gives input to counter the reset.

    The concept is not new...I first saw it implemented by 3DBuzz some years ago.

    Please give it some thought.
     
    Last edited: Aug 1, 2018
  22. Tryz

    Tryz

    Joined:
    Apr 22, 2013
    Posts:
    3,173
    Wow. So, I didn't get notified there were posts on this thread until today. Looking back, I see there are some since Jun. I'm really sorry.

    Unfortunately, I'm not getting emails for this thread and I'll look into it.

    The demo character controller I include has a "Camera" property as its first property.



    The CC will actually follow the character. That's what the 'Anchor' property is on the CC.

     
  23. Tryz

    Tryz

    Joined:
    Apr 22, 2013
    Posts:
    3,173
    Sorry about the massive delay. I never got notified there where posts here, but I have on my other threads. :(

    In the Unity Input Source is an option "Is Xbox Enabled". When that is checked, I automatically add all the Xbox specific entries to Unity's Input Manager.

    In the demo_FreeFlight scene, that option is already checked (and shouldn't be). So, it's making a call to an input that doesn't exist yet.

    The other scenes are fine and I'll fix that one.


    I just downloaded and checked the scene (on Windows 10) and it's working as advertised.

    My editor script will automatically add a 'Camera Rotate Character" entry to the Unity Input Manager. That's what defines the right-mouse-button.

    Please check if that exists or not. If it doesn't (for some strange reason), that would be the issue.

    You have to enable that option.

     
  24. Tryz

    Tryz

    Joined:
    Apr 22, 2013
    Posts:
    3,173
    Hey MrG, thanks for the suggestion.

    I tried something similar a long time ago, but didn't actually care for it. Swinging the camera to a different view due to one clip-plane-corner obstruction felt disorienting. It also lead to other clip-plane-corner obstructions which caused more swinging. I'm sure given more time and finesse it's a good solution too.

    That's one of the reasons I chose the approach Assassin's Creed Origin uses:



    The top image shows a column in the view (to the right). Orbiting the camera to the right just a tad bit more shoots it forward. It's less disorienting than changing the whole view.

    Of course. There are lots of approaches. I just had to take one that I felt was solid for most games and following what Assassin's Creed and Tomb Raider do seemed like a good option.

    It may be that I just need to expose a way for you to customize the collision result to get exactly what you want.
     
  25. jamesnw

    jamesnw

    Joined:
    Mar 23, 2013
    Posts:
    42
    Note: In advanced mode, when adding a motor, nothing is active by default. This leads to index out of range errors. It took awhile before I realized what was going on. It would have been better to automatically activate the first one by default rather than cause an error. or at least write an error message to the debug console.
     
  26. Tryz

    Tryz

    Joined:
    Apr 22, 2013
    Posts:
    3,173
    Thanks for the suggestion. I'll add that.
     
  27. jamesnw

    jamesnw

    Joined:
    Mar 23, 2013
    Posts:
    42
    You really need to put in transition on key toggle. For example, transition from 1st to 3rd on key PRESS. I don't know why you only put down and up events only. Many games have a single key to toggle the view (like 'v').

    I would also strongly suggest you put in a required start index for the transitions. You have a boolean flag for "test only in start", when you could have put in an index value instead.

    Good job on most of this though, very nice, and saves me lots of time. I'm creating a space exploration game (martianworlds.com) and I'm walking around my procedural planet using your camera. Seems to follow it perfectly out of the box. I'm happy you didn't use Vector3.up instead of translation.up, like it seems most amateurs are doing on the asset store.
     
    Last edited: Aug 9, 2018
  28. Tryz

    Tryz

    Joined:
    Apr 22, 2013
    Posts:
    3,173
    You really need to look at the documentation. Page 25 talks about how to use the transitions with a single key toggle.

    Thanks for the advice.
     
  29. jamesnw

    jamesnw

    Joined:
    Mar 23, 2013
    Posts:
    42
    I read the whole thing and didn't see it clearly. I'll check again, thanks! ;)
     
    Last edited: Aug 9, 2018
  30. jamesnw

    jamesnw

    Joined:
    Mar 23, 2013
    Posts:
    42
    Ok, I checked it out and the toggle sort of works, but it keeps bouncing back and forth. A proper toggle would trigger only on key press (down, then up). You only allow to select down or up but not "press", but it works good enough for now. Again, these are just suggestions. Obviously I can code what I need if ever.
     
  31. jamesnw

    jamesnw

    Joined:
    Mar 23, 2013
    Posts:
    42
    Your documentation (which is missing stuff) regarding "Test Only In Start" is not really clear. I thought it meant the starting motor (first one selected on game start), when in fact it means the start index of the transition. You should say instead "This checks if the key event occurs only in the start motor index of this transition" (or similar) to be clear. Now everything makes more sense lol.
     
  32. jamesnw

    jamesnw

    Joined:
    Mar 23, 2013
    Posts:
    42
    Another suggestion: working on indexes is not a good idea. You should have a separate ID to target by, or do so by name, otherwise when more are added and reordered to be clear, it all messes up. In fact, you could make this backward compatible by taking a number or name, then checking based on number (detected and converted from string) or name.
     
  33. Tryz

    Tryz

    Joined:
    Apr 22, 2013
    Posts:
    3,173
    Thanks for all the suggestions.

    Instead of spamming the forum, feel free to email me at tim@ootii.com directly. Thanks.
     
  34. jamesnw

    jamesnw

    Joined:
    Mar 23, 2013
    Posts:
    42
    You are missing "Position Blend" and "Rotation Blend" explanations in your docs.

    Sorry, is this not a support forum? ;) I'll email anything else, thanks.
     
  35. Tryz

    Tryz

    Joined:
    Apr 22, 2013
    Posts:
    3,173
    Let's be honest. You're not really asking for support. You're spamming your opinions and looking for bits and pieces to pick appart. ;)
     
  36. jamesnw

    jamesnw

    Joined:
    Mar 23, 2013
    Posts:
    42
    I'm actively building something and running into issues, so yes, it was support related. I call it "giving suggested features", but you can call it whatever lol. I was asking indirectly by giving suggestions after reading the documentation and trying to implement stuff. I should have been more direct, sorry.
     
  37. Tryz

    Tryz

    Joined:
    Apr 22, 2013
    Posts:
    3,173
    All good. :)
     
    Last edited: Aug 9, 2018
  38. silentneedle

    silentneedle

    Joined:
    Mar 14, 2013
    Posts:
    280
    @Tryz I'm currently trying to add the camera controller at runtime. Could you give me a hand on how to add the third person motor to the camera motors list?
     
  39. Tryz

    Tryz

    Joined:
    Apr 22, 2013
    Posts:
    3,173
    Hey @silentneedle ,

    Here's a working example:
    Code (CSharp):
    1. using UnityEngine;
    2. using com.ootii.Cameras;
    3. using com.ootii.Input;
    4.  
    5. public class Simple_code : MonoBehaviour
    6. {
    7.     public Transform MyTargetAnchor = null;
    8.  
    9.     public UnityInputSource MyInputSource = null;
    10.  
    11.     void OnGUI()
    12.     {
    13.         if (GUI.Button(new Rect(10f, 10f, 100f, 20f), "Add Camera"))
    14.         {
    15.             CameraController lCC = gameObject.AddComponent<CameraController>();
    16.             lCC.AnchorOffset = new Vector3(0f, 1.7f, 0f);
    17.             lCC.Anchor = MyTargetAnchor;
    18.             lCC.InputSource = MyInputSource;              
    19.  
    20.             OrbitFixedMotor lMotor = new OrbitFixedMotor();
    21.             lMotor.Name = "3rd person Fixed";
    22.             lMotor.RigController = lCC;
    23.             lMotor.Distance = 3f;
    24.             lCC.Motors.Add(lMotor);
    25.  
    26.             lCC.ActivateMotor(lMotor);
    27.         }
    28.     }
    29. }
    This should give you an example of how to change the CC and motor parameters. :)
     
    silentneedle likes this.
  40. claudius_I

    claudius_I

    Joined:
    May 28, 2017
    Posts:
    141
    Hi
    how can avoid the camera shake when up stairs or down stairs?
     
  41. Tryz

    Tryz

    Joined:
    Apr 22, 2013
    Posts:
    3,173
    Typically the camera is just following the anchor (character). So, if your character is popping up or down stairs, the camera will too.

    What you can do is add a middle-man that allows you to smooth movement. In fact, I include a Basic Camera Anchor component that you can use. I talk about it more here: Camera Anchors.

    In that link, I also include example code for a super simple camera anchor. You can customize that to get exactly what you want.
     
  42. reinaldf

    reinaldf

    Joined:
    Nov 24, 2017
    Posts:
    2
    Hi
    I just got your asset, tried using it on my project and noticed that when camera detected collision (to the ground) and if I zoom in, it get too close to the target (player) and which zooms too close that I only see its torso. If I adjust the zoom min distance, it would compromise the minimum distance when no collision detected. Is there a way that I can limit the zoom when camera is collided on ground?
    Attached are screenshots of what I experience with zoom in + floor collision and of what I only expect to be Collision_ZoomInProblem.PNG Collision_ZoomInGoal.PNG
     
  43. Tryz

    Tryz

    Joined:
    Apr 22, 2013
    Posts:
    3,173
    Unfortunately, not out-of-the-box.

    The zoom simply keeps the value that was set whether it collided with something or not.


    I did play around a little and we can change that behavior with a small bit of code. If you open the CameraController.cs and go to line 1381, you could change the "_ZoomMin" value to be something like this:

    mTargetFOV = Mathf.Clamp(mTargetFOV + lFrameFieldOfView, (mHadCollided ? mOriginalFOV : _ZoomMin), lZoomMax);

    What this basically says is that if we detect a collision, go back to the original zoom.

    However, I think this is really just a starting point.
    How far should it really un-zoom?
    When the collision is no longer there, should we re-zoom?
    etc.

    So, there's a lot to think about. But, if you're interested in customizing things you can do it in the code I define above.
     
    hopeful likes this.
  44. silentneedle

    silentneedle

    Joined:
    Mar 14, 2013
    Posts:
    280
    @Tryz After adding the camera controller and motor at runtime (as described here) I call cameraController.SetTargetForward(transform.forward, 0); (everything in Awake()) to instantly set the camera behind the newly spawned character. Is that the correct way to do? I'm asking because sometimes the mouse input doesn't work, and it seems it's related to SetTargetForward.

    p.s. could you please add a public bool which allows to check if SetTargetYawPitch & SetTargetForward is running?
     
    Last edited: Sep 4, 2018
  45. ChaosriftGames

    ChaosriftGames

    Joined:
    Aug 25, 2017
    Posts:
    21
    Top/Down camera also known as Isometric view.

    I've been struggling to get the right options for this and nothing seems to be working. "3rd Person Fixed" seems to be the best fit over the "Top Down" camera. But I'm getting just the character's head. Or the camera will scroll around first. Moba is not what I need either as the camera goes all over the place.

    I need just in just getting the camera over the player's head and staying there. Granted I need more than a basic "Tripod" setup which is why I'm doing Camera Controller.
     
  46. Tryz

    Tryz

    Joined:
    Apr 22, 2013
    Posts:
    3,173
    You can use that or SetTargetYawPitch(). My only suggestion is that you set the speed argument to 0f. This means do it instantly. Otherwise it can take a couple of frames to move to the position over time. During that time, I would ignore input.

    Yeah. I'll add that.
     
  47. Tryz

    Tryz

    Joined:
    Apr 22, 2013
    Posts:
    3,173
    Hey @ChaosriftGames , What you're asking for seems pretty simple. So, maybe I'm missing something. Here's a little test that I did...


    With this, the Top Down motor won't move around due to the edge panning, grip, etc. It just stays fixed over the character's head and stays there (even as the character moves).

    I'm hoping this helps.
     
    ChaosriftGames likes this.
  48. ChaosriftGames

    ChaosriftGames

    Joined:
    Aug 25, 2017
    Posts:
    21
    Almost there. The settings you gave worked wonderfully, until the game grid is bigger than 100. But that's a simple fix unless it's an endless world game. I did a quick Cam test while following your "Ripper Danger Room" tutorial. To get "almost" the position I want I had to change the actual camera rotation on the X axes 25 degrees (for now). You have all the settings for height and distance tuning, but no rotations :p

     
  49. Tryz

    Tryz

    Joined:
    Apr 22, 2013
    Posts:
    3,173
    You can change that limit in the motor. Setting the 'Max Bounds' to 0 will disable that limit.

    For the top down, it will stay at the rotation you set. So, you should be able to rotate using Unity's normal tools and then set the anchor offset as needed.

    That all should work. :)
     
  50. eblumrich

    eblumrich

    Joined:
    Nov 12, 2015
    Posts:
    63
    I apologize if this has been addressed before, but after reading through, I didn't see it- perhaps I missed it.

    My question:

    Is it possible to have the camera move with the motion of the mouse, without depressing the LMB?

    EDIT: This is in the context of "3rd person follow"

    GREAT product, BTW.