Search Unity

Camera Controller Release

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

  1. TeagansDad

    TeagansDad

    Joined:
    Nov 17, 2012
    Posts:
    957
    Yes, it is. Just set the View Activator property on the Unity Input Source to "none":

    upload_2018-9-11_10-53-2.png
     
    Tryz likes this.
  2. eblumrich

    eblumrich

    Joined:
    Nov 12, 2015
    Posts:
    105
    Awesome!
     
    Tryz likes this.
  3. sky_dragon

    sky_dragon

    Joined:
    May 27, 2016
    Posts:
    32
    This asset is very good, but can you tell me that the files are necessary, the entire asset is too big, I am not very programming, thank you!
     
  4. Tryz

    Tryz

    Joined:
    Apr 22, 2013
    Posts:
    3,402
    The update I'm working on will get rid of this demo bloat. For now, you can get rid of these folders:

     
    Willbkool_FPCS and hopeful like this.
  5. sky_dragon

    sky_dragon

    Joined:
    May 27, 2016
    Posts:
    32
    Thx for your replying, one more question is where is the Object Browser? PS: TIM图片20180915220321.png
     
  6. Tryz

    Tryz

    Joined:
    Apr 22, 2013
    Posts:
    3,402
    It's in your development environment (Visual Studio or Monodevelop). I use Visual Studio and you can find it under the 'View' menu item. I know Monodevelop has it too... I just forget where it's located.
     
  7. sky_dragon

    sky_dragon

    Joined:
    May 27, 2016
    Posts:
    32
    Thx!!!
     
    Tryz likes this.
  8. dinhvanvo1987

    dinhvanvo1987

    Joined:
    Aug 4, 2018
    Posts:
    4
    I have a question: How to rotation camera when mouse move? (don't use left mouse or right mouse)
     
  9. Tryz

    Tryz

    Joined:
    Apr 22, 2013
    Posts:
    3,402
    Just set the View Activator property on the Unity Input Source to "none":

     
  10. Tryz

    Tryz

    Joined:
    Apr 22, 2013
    Posts:
    3,402


    Before updating, PLEASE READ THIS!

    This update REQUIRES that you delete your 'Assets\ootii' folder and re-import the assets.

    Today I'm pushing up a massive update to all my assets. The primary goal is to support Unity's Assembly Definition Files, but there's some other cools stuff as well:

    1. Assembly Definition File support
    2. New character wizard (for the Motion Controller)
    3. Restructure folders so demo files are in one place (easy to remove)
    4. Smaller download size

    Please back-up your project and wait for all my assets (that you own) to be updated by Unity. :)

    As always, I'm here to help.
     
    hopeful and Willbkool_FPCS like this.
  11. silentneedle

    silentneedle

    Joined:
    Mar 14, 2013
    Posts:
    280
    @Tryz was this added in the last update? If not, could you provide me a temporary solution?

    Another q, how would you add a recoil to the camera controller?
     
    Last edited: Oct 1, 2018
  12. Tryz

    Tryz

    Joined:
    Apr 22, 2013
    Posts:
    3,402
    I didn't for the last push as I was trying to minimize changes. However, you can add this to the YawPitchMotor.cs class (line 320).

    Code (CSharp):
    1.         /// <summary>
    2.         /// Determine if a target yaw, pitch, for forward is set
    3.         /// </summary>
    4.         public bool IsTargetSet
    5.         {
    6.             get
    7.             {
    8.                 if (mTargetYaw != float.MaxValue) { return true; }
    9.                 if (mTargetPitch != float.MaxValue) { return true; }
    10.                 if (mTargetForward.sqrMagnitude != 0f) { return true; }
    11.  
    12.                 return false;
    13.             }
    14.         }
    This will allow you to test the active motor (by converting it to a YawPitchMotor first.

    Code (CSharp):
    1.             YawPitchMotor lMotor = this.ActiveMotor as YawPitchMotor;
    2.             if (lMotor != null && lMotor.IsTargetSet)
    3.             {
    4.                 // ...
    5.             }
    This will be part of the next push.
     
    silentneedle likes this.
  13. Tryz

    Tryz

    Joined:
    Apr 22, 2013
    Posts:
    3,402
    You've got a couple of options:

    1. Call the CC.Shake(range, strengthX, strengthY, duration) function. With this, I'll do a random camera shake.

    2. Shake or recoil using just the Main Camera. This is what I do with my shake... I wiggle the Main Camera that's inside the Camera Controller. Then, I put the Main Camera back to 0, 0, 0 when done. This works nice because it doesn't change the CC's position relative to the character, but it does create a movement effect.

    3. If you really want the whole camera angle to change permanently like I do in my Shooter Motion Pack, you can use the SetTargetYawPitch() function. I grab the local yaw & pitch, add the values I want, and call the function.
     
    silentneedle likes this.
  14. silentneedle

    silentneedle

    Joined:
    Mar 14, 2013
    Posts:
    280
    Thanks, that works, but it does seem to return true sometimes, even if SetTargetYawPitch is finished, any idea?
     
  15. Tryz

    Tryz

    Joined:
    Apr 22, 2013
    Posts:
    3,402
    Is it taking longer than you expect to return 'false' or is it just never doing it?

    If the SetTargetYawPitch() includes the 'auto clear' parameter (which is true by default), it should reset the target variables when the goal is reached. I can see it taking longer if the character is rotating while the camera is rotating... but, it should eventually get there.
     
  16. silentneedle

    silentneedle

    Joined:
    Mar 14, 2013
    Posts:
    280
    Auto clear is set. It keeps locked and the camera rotation doesn't change at all.

    edit: I've found another problem with the latest version, when building the player I receive the following error:

    Code (CSharp):
    1. Assets/ootii/Assets/Framework_v1/Code/Helpers/AssetHelper.cs(5,7): error CS0246: The type or namespace name `UnityEditor' could not be found. Are you missing an assembly reference?
    edit2:

    When calling
    Code (CSharp):
    1. cameraController.SetTargetYawPitch(0, cameraMotor.LocalPitch, 200f);
    mTargetYaw (sometimes!) keeps 0 instead of float.MaxValue.
     
    Last edited: Oct 4, 2018
  17. Tryz

    Tryz

    Joined:
    Apr 22, 2013
    Posts:
    3,402
    I've just pushed out updates to fix the build error.

    You won't need to delete 'Assets/ootii' for this update. It will just go on top of the last update.

    I'm not seeing that in my tests, but it may have to do with your exact setup. It's probably best if you just email me a small project where this is happening. This way I have your exact settings and calls.

    Please email it to tim@ootii.com.
     
  18. Michal_Stangel

    Michal_Stangel

    Joined:
    Apr 17, 2017
    Posts:
    151
    Hello,

    Is there any event firing every time when camera position, rotation or FOV has been changed? I currently use "MotorUpdated", but it fires every frame. I used it to recalculate frustum height and deriving scale of health bars and floating texts from that. But it seems to be a bit unnecessary do it even if camera doesn't move.
     
  19. Tryz

    Tryz

    Joined:
    Apr 22, 2013
    Posts:
    3,402
    No, just the "MotorUpdated" event you found.

    Since I'm moving the Camera Rig GameObject, you could have an external component that checks for a position or rotation change and then do your work. It's just not something that's inside the Camera Controller directly.
     
  20. Mijndert

    Mijndert

    Joined:
    May 5, 2017
    Posts:
    4
    Hi, I use the camera controller on a tank. It works perfect when not moving, but when I start driving the camera wants to look forward, so it's hard to look around when driving. Is there an easy fix for this?
     
  21. Tryz

    Tryz

    Joined:
    Apr 22, 2013
    Posts:
    3,402
    If you're using one of the 3rd Person motors, that's expected as the camera rig is always going to try to look towards the anchor. If you're moving forward, the cameras will be pulled along and tend to move behind the anchor causing them to look forward. This is the way traditional action adventure games like Assassin's Creed and Tomb Raider work.

    For a tank, I'm really not sure what you're trying to achieve. But, you may find one of the other camera motors (ie the 1st Person motor) works best.

    I did have someone use the CC with a car racing game and that seemed to have worked well for them. They used transitions to activate different camera views. However, I don't know about the tank.
     
  22. Mijndert

    Mijndert

    Joined:
    May 5, 2017
    Posts:
    4
    I have a 3rd person view of the tank like this, Tank.png and the tank's turret is rotated to where you look. When not moving I can look around and this works fine. Is there no way to edit the code so it's the same when moving?
     
  23. Tryz

    Tryz

    Joined:
    Apr 22, 2013
    Posts:
    3,402
    Ok. That was different than what I was thinking.

    Use the 3rd Person Fixed motor and make sure "Rotate With Anchor" and "Rotate Anchor" are not checked. That will allow you to rotate the camera while moving. Obviously you'll have to rotate the tank some other way.

    As an example, open my demo_3rd_Person_Style scene then, ensure the Camera Controller looks like this:


    When you hit 'play' and press 'W', the character will move forward and you can continue to orbit around him with the RMB pressed... the character's direction won't change.
     
  24. Mijndert

    Mijndert

    Joined:
    May 5, 2017
    Posts:
    4
    Thank you! This was exactly what I was looking for, it works perfectly now.
     
    Tryz likes this.
  25. Cywizz

    Cywizz

    Joined:
    Oct 5, 2017
    Posts:
    17
    I just bought this asset with both your input and motion controller and I must say your quality and documentation is fantastic! The motion controller saved me a hell of a lot of time and everything is really well structured.

    The last few days I picked up something strange and I am hoping you could guide me in the right direction.

    Here is my setup:
    I have an UMA character setup with your motion controller and it works great. I use the adventure style third person view and the distance from the anchor is 3.
    Now every now and then, when I run the game, the camera moves into first person view. When I stop the game and change the distance to 4, then it works again for a few times. (+- 3-5 times). Then all of a sudden it happens again and I go back and change the distance again back to 3 and rinse and repeat.

    Is there something I might be doing wrong or should look out for?

    Thanks!
     
  26. Tryz

    Tryz

    Joined:
    Apr 22, 2013
    Posts:
    3,402
    It almost sounds like the zoom feature is kicking in. Can you try disabling zoom to see if it still happens?

    If it doesn't, than it's probably your mouse wheel is sending a signal and I'm registering that as a zoom.
     
  27. Cywizz

    Cywizz

    Joined:
    Oct 5, 2017
    Posts:
    17
    I will try tonight and let you know. I can confirm that I have zoom enabled because when I am in 3rd person, I can zoom closer to the character, but not all the way to 1st person...
    I will disable and see if this changes
     
  28. Cywizz

    Cywizz

    Joined:
    Oct 5, 2017
    Posts:
    17
    @Tryz I disabled zoom but the issue is still there. Something is setting the Distance to 0 upon start.
    I delved in a bit more and added breakpoints in your code and this is what I found:

    In you CameraMotor class in the DeserializeMotor method line 831 you have the following line:

    lProperty.SetValue(this, lValueNode.AsFloat, null);
    I looked the the value of IValueNode which equals: \"4.00000\" but the .AsFloat converts it to 0

    The portion of the rDefinition parameter passed into the function has the following JSON value:
    \"Distance\" : \"4.00000\"
    So the above sets the Distance property on the OrbitFollowMotor class to 0 on startup, which seems weird.

    After this, it worked for a while and I could not recreate the issue consistently.
    However, I then saved the project and restarted it a few times, and every time the Distance property is set to 0 on Unity startup. So deserialization has some issue, somewhere.
     
  29. SickaGames1

    SickaGames1

    Joined:
    Jan 15, 2018
    Posts:
    1,270
    Will this camera be a replacement for Invector's TPC Shooter camera and would I be able to use the mousescroll to transition from 3rd Person to 1st Person view? If so, how?
     
  30. Tryz

    Tryz

    Joined:
    Apr 22, 2013
    Posts:
    3,402
    What's odd is that no one else is reporting an issue and I can't reproduce it.

    I'm wondering if it's a number formatting issue based on your country. What country are you in and how do you represent your numbers?
     
  31. Tryz

    Tryz

    Joined:
    Apr 22, 2013
    Posts:
    3,402
    I'm not familiar with TPC's shooter camera.

    You cannot use the mousescroll to transition like that automatically. You would have to write code that activates the transition motor when you want. So, the behavior is possible with some small bit of management code based on when you want the transition to occur.
     
  32. Cywizz

    Cywizz

    Joined:
    Oct 5, 2017
    Posts:
    17
    Hi, thanks for the reply. My localization is set to en-za (South Africa) but I am not sure how this may cause an issue. It is only this one field that is giving me a hard time.
    The only thing I can think of that might be different is that I first installed the motion controller and got everything up and running with the toned down camera controller that you ship with it. The problem already started there.
    Then only did I install the full camera controller asset hoping that it might resolve it.

    I have added a small injection script to set the value on the camera controller manually on awake, so it is not a big deal for now...thanks again for your help @Tryz
     
    Tryz likes this.
  33. silentneedle

    silentneedle

    Joined:
    Mar 14, 2013
    Posts:
    280
    Hey @Tryz,

    it seems I've fixed my problem by changing the EPSILON const from 0.0001f to 0.001f in the YawPitchMotor. Do you know if there is any drawback by reducing the precision of this value?

    p.s. It seems that this problem only occurs on MacOS machines.
     
    Last edited: Nov 27, 2018
  34. Tryz

    Tryz

    Joined:
    Apr 22, 2013
    Posts:
    3,402
    I think you're fine. I'm not sure why that would only be an issue on MacOS, but it may have to do with how it unpacks numbers. I'm just not sure.

    Your solution should be fine.
     
  35. Chaz32621

    Chaz32621

    Joined:
    Apr 17, 2015
    Posts:
    199
    Hello, love the asset. Was just wondering if there was an easy way to transition from one Anchor to another over time?

    So for example currently using the MOBA top down cam motor. After the game object(Anchored one) is destroyed a script selects a new anchor and at the moment the camera auto snaps to that new anchor. How can I get it to travel per say to the next anchor? Per a amount of time??
     
  36. Tryz

    Tryz

    Joined:
    Apr 22, 2013
    Posts:
    3,402
    Hey @Chaz32621 ,

    Normally, I'd say to use a transition motor. So, imagine you had two top-down motors (called #1 and #2) and a transition motor for each (#3 and #4). #1 is active and following an anchor. Through code, you'd set the new target anchor on #2 and then activate transition motor #3. This would have the camera move from #1's anchor to #2's anchor smoothly. Once that transition was done, #2 becomes active.

    You can imagine the #4 is setup to transition from #2 back to #1.

    The problem is that if you destroy the anchor before the transition is done. You'd have to play with the "Position Blend" settings on the transition motors. For example, setting to "Static Start" should allow you to run with a destroyed anchor as the starting motor's position will be static. You'll have to test that.

    I hope that makes sense.
     
  37. Chaz32621

    Chaz32621

    Joined:
    Apr 17, 2015
    Posts:
    199
    I think I have it but still seeing it snap, with a lag now. This is sorta of a Tower Defense game mode, but I like the top down camera and want to use the extra things it has with it to accomplish this.

    Here is a snippet of my code.

    Code (CSharp):
    1.  --Call Functions
    2.  
    3. private void Start()
    4.         {
    5.             cameraController = GameObject.Find("Camera Rig").GetComponent<com.ootii.Cameras.CameraController>();
    6.             Cam1 = cameraController.GetMotor("Cam1");
    7.             Cam2 = cameraController.GetMotor("Cam2");
    8.             Tran1 = cameraController.GetMotor<com.ootii.Cameras.TransitionMotor>("Cam1 To Cam2");
    9.             Tran2 = cameraController.GetMotor<com.ootii.Cameras.TransitionMotor>("Cam2 To Cam1");
    10.             Instance = this;
    11.         }
    Code (CSharp):
    1. public void AddTarget(GameObject tgt)
    2.         {
    3.             tgtgameobject.Add(tgt);
    4.             SelectTarget(tgt);
    5.          
    6.         }
    7.  
    8. public void SelectTarget(GameObject tgt)
    9.         {
    10.             if(target != null || tgtgameobject.Count ==0) return;
    11.  
    12.             if(target == null && tgtgameobject.Count > 0)
    13.             {
    14.                 for(int i = 0; i < tgtgameobject.Count; i++)
    15.                 {
    16.                     if(CamUse == 0)
    17.                     {
    18.                         cameraController.ActivateMotor(Tran2);
    19.                         cameraController.Anchor = tgtgameobject.gameObject.transform;
    20.                         CamUse++;
    21.                     }
    22.                     if(CamUse == 1)
    23.                     {
    24.                         cameraController.ActivateMotor(Tran1);
    25.                         cameraController.Anchor = tgtgameobject.gameObject.transform;
    26.                         CamUse--;
    27.                     }
    28.                 }
    29.             }
    30.         }
    I feel like I might be missing a little something?? Should I disable both cams? Would I still get a follow from whichever cam is in use at that time? Only other thing I can think of is before transition disable both cams, change anchor then activate tran.
     
  38. Chaz32621

    Chaz32621

    Joined:
    Apr 17, 2015
    Posts:
    199
    Ah think I got it, will need to do more testing but I went ahead and just modified the code in the WorldMotor.

    Added this on line 300 seems to help do the trick will need to edit the speed some.

    mPositionTarget = Vector3.MoveTowards(mPositionTarget , lAnchorPosition - (RigController._Transform.forward * _MaxDistance) , Time.deltaTime * 15);
     
    Last edited: Dec 3, 2018
    Tryz likes this.
  39. ToThinkIsToCreate

    ToThinkIsToCreate

    Joined:
    Jun 15, 2017
    Posts:
    16
    Would your code work for mobile joystick controls, I have been working on my camera code for awhile lol, I want third person camera code for my marble as it travels back and forth
     
  40. KeithBrown

    KeithBrown

    Joined:
    Apr 1, 2017
    Posts:
    191
    I feel like this should be an easy question to answer but I could not get it to work and thought I would ask before delving into it. How can i stop the camera from rotating completely? I want it to just follow my character and when the right joystick is moved not rotate. I thought there might be a flag somewhere on the controller but for the life of me I cannot find it.
     
  41. Tryz

    Tryz

    Joined:
    Apr 22, 2013
    Posts:
    3,402
    It will, but you need to create a custom "Input Source". This is what connects your input solution (mobile or not) to any of my assets.

    Check out this post and video on Input Sources.
     
  42. Tryz

    Tryz

    Joined:
    Apr 22, 2013
    Posts:
    3,402
    Hey Keith,

    I'm assuming you're talking about the 3rd Person Motors. If you don't want any rotation, I'd use the Fixed Motor. You can set it back how you want and it won't rotate based on input. The Fixed Motor will still use collision (if you want) and can be transitioned in and out of.

    I hope that makes sense. :)
     
  43. sparkwd

    sparkwd

    Joined:
    Aug 12, 2018
    Posts:
    12
    Hi @Tryz I’m loving your asset! It’s a huge timesaver. All the standard functionality has worked great, and quickly, right out of the box. All I’m looking to do now is extend some minor functionality to get the camera to re-center behind the player after a delay of the mouse being inactive.

    To spare you the boredom of my trial and error, here is the basic code I’m working with now.

    Code (CSharp):
    1.  
    2. public GameObject Player;
    3. public GameObject CameraRig;
    4. public float timeOut = 3.0f;
    5. public float cameraReturnSpeed = .1f;
    6. private float timer = 0f;
    7.  
    8. void Update()
    9. {
    10.  
    11.     // Reset timer when user moves the mouse
    12.     timer += Time.deltaTime;
    13.     if (Input.GetAxis("Mouse X") != 0 || Input.GetAxis("Mouse Y") != 0)
    14.     {
    15.         timer = 0f;
    16.     }
    17.  
    18.     // When the user hasn't moved the mouse in a while
    19.     if (timer > timeOut)
    20.     {
    21.  
    22.     // Hoping to replace this next line with a camera rotation transition
    23.     CameraRig.transform.forward = Player.transform.forward;
    24.     timer = 0f;      
    25.  
    26.     }
    27. }
    28.  
    All I want to do now is hook into the right method to perform a smooth rotation on the camera around the character so that it centers behind him and shares the same
    transform.forward
    with him.

    I’ve tried hooking into your
    OnControllerLateUpdate
    method in CameraController.cs, but I’m not sure that’s the correct method so then I just tried to access the basic transform of the camera game object. It works abruptly so I’m not able to apply an easing transition with
    Quaternion.Slerp
    from the way I’m doing it – which is clearly wrong. So I thought I would just ask you where to hook in. I hope that makes sense.

    Anyway, thanks for any help you can offer. By the way, I'm also using your Character Controller in case it conflicts with my approach. Thanks!
     
  44. Tryz

    Tryz

    Joined:
    Apr 22, 2013
    Posts:
    3,402
    Hey @sparkwd ,

    This should be super easy.

    The line after your comment (// Hoping to replace this next line with a camera rotation transition) you want to add this code:

    Code (CSharp):
    1. CameraController lCC = CameraRig.GetComponent<CameraController>();
    2. lCC.SetTargetYawPitch(0f, 0f, 360f, true);
    The function will force the third person motor to rotate to the 0 degree position (yaw and pitch) relative to the character's direction. So, this is behind him sharing the transition forward.

    The third parameter is the speed (360 degrees per second) at which the rotation to the targets occur. You can set it to 0f and it will be instant.

    That should do it.
     
    sparkwd likes this.
  45. sparkwd

    sparkwd

    Joined:
    Aug 12, 2018
    Posts:
    12
    Thanks @Tryz, that's exactly what I needed. Works perfectly. Thanks!
     
    Tryz likes this.
  46. holodevice

    holodevice

    Joined:
    May 29, 2017
    Posts:
    28
    Hi Happy new year!!!

    Camera Controller - What is the plan for updating to support UWP in 2018.3 ? The Scripts need fixes.

    Works on 2017+ nice.
     
  47. Tryz

    Tryz

    Joined:
    Apr 22, 2013
    Posts:
    3,402
    Hi,

    I’m using it on 2018.3 (non UWP) now and it’s working fine. I haven’t tried UWP with Unity 2018.3, but I’ll do that.

    Unfortunately, UWP is a nightmare from a Unity standpoint. Unity changes the API pretty regularly and breaks things. I’ll give it a try and see what I get this time. ☹

    [EDIT]
    In my tests, UWP on Unity 2018.3 is working fine.
     
    Last edited: Jan 20, 2019
    TeagansDad likes this.
  48. inthemilkywat

    inthemilkywat

    Joined:
    Dec 29, 2013
    Posts:
    56
    I'm trying to make my camera lock on to a target but it stutters when I move. Here's the code I'm using to set the camera to face the target. Using the third person fixed camera.

    Code (CSharp):
    1. void Update()
    2.     {
    3.         Vector3 forward = (strafeTarget.position - camera.Transform.position).normalized;
    4.         camera.SetTargetForward(forward, 360);
    5.     }
     
  49. Tryz

    Tryz

    Joined:
    Apr 22, 2013
    Posts:
    3,402
    Hey @inthemilkywat ,

    I'm guessing that your target is moving out of sync with the player movement and camera movement. Since we're forcing the rotation of the camera, the rotation could be a frame behind the movement and create the stutter.

    For example:

    1. Anchor moves
    2. Camera moves
    3. Camera rotates to target
    4. Target moves

    or

    1. Target moves
    2. Anchor moves
    3. Camera moves
    4. Camera rotates to target

    You'll get different results based on the order.

    This is a standard game development issue based on the order that you do things.

    Said another way, the SetTargetForward() doesn't change the camera rotation immediately. Instead, it sets a target rotation internally. which means you could be setting an old target position before your target moves in the frame.

    If your player is moving and your camera is moving and your target is moving, make sure your target moves before the camera uses its position to create the direction.

    The "Force Update" and "Use Fixed Update" options can be used to help control this depending on how you do your update cycles. In the case of my character controller, I don't use "Force Update" and instead, the character controller calls the Camera Controller's RigLateUpdate() function to ensure the camera updates after the player moves and rotates. Then, I make sure that happens after the target moves and rotates to keep things in sync.

    I hope all that makes sense.
     
  50. inthemilkywat

    inthemilkywat

    Joined:
    Dec 29, 2013
    Posts:
    56
    Using fixed update removed the stuttering. Thanks.
     
    Tryz likes this.