Search Unity

[Released] Character Movement Fundamentals - A Rigidbody-based Character Controller

Discussion in 'Assets and Asset Store' started by JanOtt, Jul 1, 2019.

  1. JanOtt

    JanOtt

    Joined:
    Apr 23, 2019
    Posts:
    183

    Hi everyone!​

    I'd like to introduce you to Character Movement Fundamentals, a rigidbody-based character movement system for Unity.

    Put simply, it's a collection of scripts, components and prefabs that will help you quickly set up characters that can move around and react to any 3D game environment in a physically believable way.

    Everything in this package is designed to be as versatile and adaptable as possible - whether you're creating a fast-paced first-person shooter, an atmospheric third-person adventure game or a 2.5D sidescoller, this package will provide all the necessary fundamentals you need.
    Features:

    - In-depth user manual.

    - Fully documented source code.

    - Versatile, highly customizable character controller system.

    The included character controller can handle all kinds of terrain, smoothly walks up and down slopes and stairs without losing ground contact and can even slide down slopes that are too steep.

    In addition to that, it can be rotated freely at runtime, allowing for
    interesting gameplay possibilities (walking on ceilings or on a miniature planet [...]).

    To optimize your game for any type of platform, you can choose from three different ground detection methods.

    Finally, all movement-related properties (movement speed, air control, jump speed, step height [...]) can be adjusted to fit any type of gameplay.

    - All-purpose camera system
    The included camera system is well suited for any type of camera perspective (first-person, third-person, top-down [...]) and features built-in camera rotation smoothing, invertible input axes and adjustable vertical camera angle limits.

    - Two example scenes that showcase all the possibilities of the package.

    - 12 ready-to-use controller prefabs, that can "drag'n'dropped" into any scene and just work, no further setup required.

    - A collection of basic environment building blocks and a fully rigged and animated low-poly character model, both of which are great for quick prototyping.

    ----------​
    If you have any questions about this asset and its playable demo or if you'd like to give me some feedback (which is always very much appreciated), please feel free to do so, either here in the forums or directly via email at support@j-ott.com.

    Thanks for your time and have a great day!
    - Jan
     

    Attached Files:

    Last edited: Apr 30, 2020
  2. p_hergott

    p_hergott

    Joined:
    May 7, 2018
    Posts:
    414
    this looks really well done, very versatile. 2 quick questions, would I be able to run 2 character controllers and cameras at the same time? and does the camera have a ability to zoom in/switch position?
     
  3. JanOtt

    JanOtt

    Joined:
    Apr 23, 2019
    Posts:
    183
    Thanks p_hergott!

    You can easily run multiple character controllers in the same scene! Here's an example I just threw together:

    Splitscreen.png

    For the split-screen effect, all you need to do is adjust the 'Viewport Rect' settings of the player cameras, which only takes a few seconds.

    There's no 'zoom script' included in the package (yet), but implementing a zoom function would be fairly easy. If you're interested, just send a mail to support@j-ott.com and I'll gladly help out with that.

    Regarding switching camera positions, I'd need a bit more information about what you're trying to do - do you want to have two characters in a scene sharing one camera (that can switch between these two characters) or something else entirely?
     
  4. p_hergott

    p_hergott

    Joined:
    May 7, 2018
    Posts:
    414
    Well im 3/4 done a split screen xbox project. And the one thing i keep revisiting is the camera controller. For zoom, im thinking, for a over the should aim mode.
     
  5. p_hergott

    p_hergott

    Joined:
    May 7, 2018
    Posts:
    414
    and can the camera target be set dynamically?
    also while im asking hahaha, I see the controller has a jump, does it also have a sprint? (my controller im using I built myself, so doing minor modifiers and stuff shouldn't be a problem.
     
  6. p_hergott

    p_hergott

    Joined:
    May 7, 2018
    Posts:
    414
    haha I almost feel bad for all the questions, but I do truly like what I see though, looking through the images, video and manual. it really does look like an outstanding controller.
     
  7. JanOtt

    JanOtt

    Joined:
    Apr 23, 2019
    Posts:
    183
    Thanks for the kind words!
    Ah, now I get it! This kind of zooming/aiming can easily be implemented with this asset. It basically comes down to changing the camera's offset and field-of-view a bit whenever the player is holding down the 'aim down' button.
    As of right now (version 1.1), all cameras are child objects of the character controllers. However, since the whole system is very modular, you could easily make the camera its own independent gameobject and have it follow different targets dynamically.
    Currently, there's no sprint functionality implemented in the controllers (there could be in the future, if there's enough interest in more advanced movement). The scripts are very adaptable though, so adding sprinting should be fairly straightforward, depending on how complex your sprinting system needs to be.

    Like I said before, if you happen to run into any problems with the asset or need help implementing something specific, just feel free to contact me via the support email and I'll try to answer in more detail.
     
  8. JanOtt

    JanOtt

    Joined:
    Apr 23, 2019
    Posts:
    183
    I'm happy to announce that 'Character Movement Fundamentals' has just been upgraded to version 1.1. Here's a list of the changes:

    - Replaced old showcase scene with new version (now with a proper controller selection menu).
    - Polished controller prefab settings.
    - Replaced 'ApplicationControl' and 'ChangeControllerType' scripts with new 'DemoMenu' script, which will now handle switching between different controller prefabs.
    - Added 'DisableShadows', 'FPSCounter' and 'PlayerData' scripts, all of which are used in the new showcase scene.
    - Decreased scene light intensity to '0.7'.
    - Removed all (unnecessary) 'Showcase' controller prefabs, all example scenes now use the controller prefabs included in the project.
    - Added 'MouseCursorLock' script, which provides basic mouse cursor locking functionality. Old (unstable) 'FocusMouse' script was removed.
    - Updated user manual to reflect changes.

    This update mostly consists of streamlining the showcase scene(s) and all included controller prefabs, but there's also some new content in there (a proper mouse locking script, for example).
     
  9. tequyla

    tequyla

    Joined:
    Jul 22, 2012
    Posts:
    335
    Hello,

    concerning the top down view, is it possible to add click and point move ?

    thanks.

    Teq
     
  10. JanOtt

    JanOtt

    Joined:
    Apr 23, 2019
    Posts:
    183
    There's currently no "point-and-click" type controller included in the package. But it's definitely possible to implement that kind of movement with this package by writing some custom movement logic.

    I'll definitely add a dedicated controller prefab for this in a future update if there's a demand for it, though!
     
  11. Sehlor

    Sehlor

    Joined:
    Feb 10, 2012
    Posts:
    199
    I can vouch for click to move for Top-Down, otherwise its an excellent product!
     
  12. HellGate94

    HellGate94

    Joined:
    Sep 21, 2017
    Posts:
    132
    Hello.

    Looks interesting, but can you tell me a bit more on how it is done? I assume it's a kinematic not dynamic character controller so the interactions with dynamics are reconstructed my hand. i'm using a seesaw test to check if character controllers are suitable for me. would you be so kind and show me how it acts when the character jumps on a dynamic seesaw and with a heavy object falling on the other end while standing on it (and maybe one where he walks on an unstable physics object like a chain bridge)?

    thanks
     
    Last edited: Aug 4, 2019
  13. JanOtt

    JanOtt

    Joined:
    Apr 23, 2019
    Posts:
    183
    Well, seems like there is a demand, so I'll be sure to sure to look into it for the next update!

    Put very simply, the character movement system in this package is a combination of (dynamic) rigidbody physics and a raycast-based ground detection system to get the best of both worlds, so to speak.

    Regarding your seesaw test: As of right now, this package is probably not the best choice for the type of environment interaction you're looking for. By default, the controllers don't exert any downwards force on the rigidbodies they're standing on (which would be necessary for a seesaw to work). Likewise, the controllers don't feature an inertia system yet (also necessary for the seesaw physics).

    I can think of few ways to convincingly "fake" the physics interaction you're looking for, but a 100% physics driven rigidbody controller might be a better choice here.

    Hope that helps!
     
  14. HellGate94

    HellGate94

    Joined:
    Sep 21, 2017
    Posts:
    132
    well no other character controller i tested so far passed this test so thats good info (for you, for me it means i need to keep searching :D)

    making a dynamic rigidbody controller is a pain and i pretty much gave up already because the physics engine causes several bugs and without source code i cant adjust / fix it.

    but oh well. good luck with your asset!
     
  15. superjayman

    superjayman

    Joined:
    May 31, 2013
    Posts:
    185
    What sort of moving platforms does it support and how does it handle the orientation of moving platforms?

    e.g. if I'm inside a school bus that is a physics based vehicle, can I walk around the inside of the bus, and what happens to character orientation when the bus is turning?
     
  16. JanOtt

    JanOtt

    Joined:
    Apr 23, 2019
    Posts:
    183
    Currently, all included controller prefabs support kinematic rigidbody platforms that use trigger zones (trigger colliders) to determine if a character is standing on top of them. As of now, the orientation/rotation of the moving platform does not affect the rotation of the character standing on it.

    I'm currently doing some tests to see if I can come up with a system that doesn't require trigger zones and could also handle rotating the character at the same time. So far, I haven't found a good solution yet, but I'll keep at it.
    That sounds like a tricky game mechanic to implement. Since the bus would need to be a dynamic rigidbody, this is currently not possible with this package.

    Do you have an example of an existing game that implemented this mechanic successfully? I'd love to see this in action!
     
  17. jh092

    jh092

    Joined:
    Sep 2, 2018
    Posts:
    55
    Hi there and thank you for you great product. I am using your first person prefab and would like to know if I can make the camera movement only happen when a mouse button is down instead of all the time as it does now?

    I’d need the user to be able to move his mouse in the game without moving the view.

    Many thanks and best wishes
     
  18. JanOtt

    JanOtt

    Joined:
    Apr 23, 2019
    Posts:
    183
    Hi jh092!
    That's easily done! All you need to do is create a custom script, extend the CameraController script and override its GetInput() function. There's also a chapter in the manual on this topic (4.4.2 - Overriding the Camera Controller, page 31), if you're interested.

    Check out the file I attached below called "CustomCameraController": It's a very basic example of how to implement that kind of camera behaviour. Just import it into your project and use it to replace the regular camera controller component in one of the prefabs (or you might want to create a new custom prefab first).

    In the 'FirstPersonWalker', you'll find the camera controller script under 'FirstPersonWalker -> CameraRoot -> CameraControls'.

    Side note: Make sure there's only one camera controller script attached to the gameobject at the same time.

    I hope that helps! If you have any further questions (or if anything's not working correctly), please feel free to contact me via the support email (support@j-ott.com). Or just reply in this thread, both options work for me!
     

    Attached Files:

    sarynth likes this.
  19. jh092

    jh092

    Joined:
    Sep 2, 2018
    Posts:
    55
    Ah I see, thank you so much for the super fast response, this is exactly what I needed too.

    John
     
  20. jh092

    jh092

    Joined:
    Sep 2, 2018
    Posts:
    55
    Hi again, sorry I do have one more question if I may...

    I'm trying to save the player position and rotation so that I can save and load my game levels, returning back to where I was.

    I can save the position just using the FirstPersonWalker transform.position that's fine, but my issue is with the rotation. I have tried many different things using the FirstPersonWalker/CameraRoot/CameraControls.transform.rotation but not having much success.

    For rotation, on save I'm using:

    CameraControls.transform.rotation.eulerAngles.x
    CameraControls.transform.rotation.eulerAngles.y - 360

    And then on load I'm using the SetCustomRotation with the above two values.

    Looks like the y is correct but the x is always wrong...

    Hope that all makes sense :)
     
  21. JanOtt

    JanOtt

    Joined:
    Apr 23, 2019
    Posts:
    183
    That should be fairly straightforward to implement. Since the rotation of 'CameraControls' is directly controlled by the 'CameraController' component ('CustomCameraController', in your case), you'll need to save (and load) the rotation values of the component instead of directly setting the transform's rotation.

    I'd love to go more into detail, since your question kind of requires a few more in-depth explanations. Would it be okay for you if we continue this by email? Just send me a copy of your comment to support@j-ott.com and I'll get back to you as soon as possible.
     
  22. revanaii

    revanaii

    Joined:
    Jun 13, 2017
    Posts:
    11
    Sooo for anyone who needs sprinting
    Code (CSharp):
    1.  
    2. public class ExtendedCameraWalkerController : CameraWalkerController
    3. {
    4.    float defaultMovementSpeed;
    5.    public float sprintingSpeed;
    6.    public KeyCode sprintingKeyCode;
    7.    public bool IsSprinting{ get; protected set; }
    8.    public UnityEvent onSprintBegan = new UnityEvent();
    9.    public UnityEvent onSprintEnded = new UnityEvent();
    10.  
    11.    protected override void Setup()
    12.    {
    13.       base.Setup();
    14.       defaultMovementSpeed = movementSpeed;
    15.    }
    16.  
    17.    void LateUpdate()
    18.    {
    19.       var wasSprinting = IsSprinting;
    20.       IsSprinting = Input.GetKey(sprintingKeyCode);
    21.       movementSpeed = IsSprinting ? sprintingSpeed : defaultMovementSpeed;
    22.       if(!wasSprinting && IsSprinting) onSprintBegan.Invoke();
    23.       if(wasSprinting && !IsSprinting) onSprintEnded.Invoke();
    24.    }
    25. }
    26.  
     
    Last edited: Aug 20, 2019
    JamesArndt, Xentar and Mythran like this.
  23. EstudioVR

    EstudioVR

    Joined:
    Jul 26, 2013
    Posts:
    127
    is it mobile ready?
     
  24. JanOtt

    JanOtt

    Joined:
    Apr 23, 2019
    Posts:
    183
    The controllers should run fine on mobile devices, performance wise. In addition to that, you can override the controllers' input calculation to implement any user input system - mobile input (via virtual joysticks, for example) included.

    I'm currently looking into including mobile controls for the next update, though. If you need mobile input out-of-the-box, you might want to wait for version 1.2, which should be ready sometime in September.

    @revanaii
    Cool, thanks for sharing that movement code! Are the UnityEvents in your code for animation purposes?
     
    EstudioVR likes this.
  25. revanaii

    revanaii

    Joined:
    Jun 13, 2017
    Posts:
    11
    JanOtt
    Yep, to hook up camera FOV tweening, particles - that kind of stuff. And thx for the great asset, so far it's the best controller I've found in terms of out-of-the box quality and complexity under the hood.
     
  26. JanOtt

    JanOtt

    Joined:
    Apr 23, 2019
    Posts:
    183
    Thanks, very glad to hear that!
     
  27. toddkc

    toddkc

    Joined:
    Nov 20, 2016
    Posts:
    207
    Hi there! Little pre-purchase question. So this looks like a great way to learn to make character controllers, which is what I'm doing obviously. I'm curious, most of these assets are only animated for third person, and don't really cover first-person with an animated avatar. I'm having a difficult time setting that up myself. Does this have something like that? For example, something that would work for first-person multiplayer (first-person, but you need to see each player avatar), or something allowing the player to swap between first and third person views? Hope this makes sense, sorry my brain is fried at the moment...
     
  28. ikemen_blueD

    ikemen_blueD

    Joined:
    Jan 19, 2013
    Posts:
    341
    I bought this character long time. At first, I thought it seems interesting to check out the code. I just tried it today. And, I'm surprised how smooth it is, its collision and penetration handling. The beauty is that this is a physics controller, interacting with physics object like plug and play, no hack no code. And you have the controllable feeling of a Kinematic controller, with smooth Camera controller to play well with it. I can't wait to learn more from this gem. I will write a good review soon :) Happy coding!!!

    Quick question: how easy is this Physics controller to support Root Motion on or off? Thanks
     
    Last edited: Sep 6, 2019
    RogDolos likes this.
  29. JanOtt

    JanOtt

    Joined:
    Apr 23, 2019
    Posts:
    183
    Hi toddkc!
    In most games nowadays, you would use a two separate character meshes for first-person and third-person view, with each having custom animations.

    For example, a regular first-person character mesh is often just two arms floating in mid-air, holding a gun.

    To accomplish things like changing from first-person to third-person view, you'd simply turn off the first-person mesh and turn on the "normal"/third-person mesh, while changing the camera perspective at the same time.

    So, to answer your question: There's currently no built-in camera switching functionality included in the package, but you could easily implement something like it yourself with a bit of coding experience in Unity.

    If you'd like to discuss this topic in greater detail, feel free to contact me via support@j-ott.com and I'll do my best to answer your questions!
     
  30. JanOtt

    JanOtt

    Joined:
    Apr 23, 2019
    Posts:
    183
    Thanks for the kind words!

    Regarding root motion controls: That's an interesting question! To be completely honest, I haven't looked too much into root motion implementation yet, but it's definitely on the list.

    The way I understand it, root motion should be relatively easy to combine with the 'Mover' component, but it most likely will require coding a new controller script (since root motion is too different from the player input based controls currently implemented).

    Hope that helps!
     
    ikemen_blueD likes this.
  31. toddkc

    toddkc

    Joined:
    Nov 20, 2016
    Posts:
    207
    Thanks for the reply. Let's forget about the switching camera part. Is there a first-person controller setup to animate a full body, and not just arms?
     
  32. JanOtt

    JanOtt

    Joined:
    Apr 23, 2019
    Posts:
    183
    Unfortunately, there's currently no first-person, full body animation setup included in the package. All animations included in the package belong to the 'Capguy' character, which is just a simple placeholder (and doesn't have any arms or legs).

    Maybe I'll include a more humanoid character in the package sometime in the future, though!
     
    toddkc likes this.
  33. toddkc

    toddkc

    Joined:
    Nov 20, 2016
    Posts:
    207
    I like the simplicity of Capguy, he just needs a CapguyStrafe and CapguyBackwards animation setup :)
     
  34. toddkc

    toddkc

    Joined:
    Nov 20, 2016
    Posts:
    207
    I went ahead and purchased this. I think there was a communication issue when I asked my question, I was over-complicating it. For the record (for anyone also curious) there is a third-person controller set up to strafe. Exactly what I needed!
     
  35. gferrari

    gferrari

    Joined:
    Jan 14, 2015
    Posts:
    135
    I try the demo of this asset and is very solid. I want to know if with the asset I can restrict the movement of the camera like this game. (Up and down and on both sides) and get the same perspective/feeling. Also know if it is easy to add animations, such as walking, opening doors, etc.

    The game is: Corpse Party 2: Dead Patient

    Thank you!
     
  36. JanOtt

    JanOtt

    Joined:
    Apr 23, 2019
    Posts:
    183
    After looking at a few gameplay videos, I can safely say that you can realize this kind of camera setup with my asset.

    Actually, a few days ago, two customers were looking to implement a very similar perspective in their games and I wrote a little example script for them. If you end up buying the asset, please contact me via support@j-ott.com and I'll send you a copy of the script, if you're interested.

    'Character Movement Fundmentals' only handles the movement aspect (including physics) of your game. Anything beyond that (like opening doors) you'll need to program yourself.

    Adding animations will require basic knowledge of the animation tools in Unity (Mecanim) and a bit of coding to hook up the animations to the character's current state and velocity. There is however a section in the manual (4.6) that outlines some of the basics.

    I hope that helps!
     
  37. jnbbender

    jnbbender

    Joined:
    May 25, 2017
    Posts:
    487
    Just picked this up. Looks good. Was wondering if there was any plans for Crouching as with the "Easy Character Movement" package?
     
  38. jnbbender

    jnbbender

    Joined:
    May 25, 2017
    Posts:
    487
    Actually I have something else. I am using the first person view but no matter what I do I cannot raise the height/view of the Actor/Camera. Any ideas?
     
  39. JanOtt

    JanOtt

    Joined:
    Apr 23, 2019
    Posts:
    183
    Crouching could be a nice addition for a future update, I'll look into it and see what I can do!
    That's odd. The only situation I can think of where you might run into problems is if you're trying to change the camera's height at runtime by moving the 'CameraRoot' object. Because that would interfere with the 'SmoothPosition' component.

    If that's the case, the easiest solution would be to just move the 'CameraControls' object instead, which is not affected by the smoothing scripts.

    If that doesn't solve the problem, please contact me via support@j-ott.com and I'll take a closer look!
     
  40. toddkc

    toddkc

    Joined:
    Nov 20, 2016
    Posts:
    207
    If you are talking about what I think you are, I had this same issue too. I am used to the capsule being my entire character, with the bottom of the capsule touching the ground. That isn't how this works. The capsule represents the torso, and you need to adjust the Collider Offset Y and Collider Height settings in the Mover script on your gameobject to adjust the height.

    If I misunderstood then disregard...
     
    Last edited: Sep 27, 2019
  41. jnbbender

    jnbbender

    Joined:
    May 25, 2017
    Posts:
    487
    Ahhh. I was curious as to why my Collider size and Collider height changed every time I played.
     
  42. toddkc

    toddkc

    Joined:
    Nov 20, 2016
    Posts:
    207
    @JanOtt can explain better I'm sure, but what I've noticed is that I can ignore the actual collider settings and change the ones on mover which will adjust the size of the collider as needed.
     
  43. jnbbender

    jnbbender

    Joined:
    May 25, 2017
    Posts:
    487
  44. JanOtt

    JanOtt

    Joined:
    Apr 23, 2019
    Posts:
    183
    That's exactly right, toddkc. The 'Mover' component overrides the collider's height and offset, based on the values set in its inspector (step height, collider height, collider thickness and collider offset).

    Thanks! I'm familiar with 'Easy Character Movement', really nice package.
     
  45. jnbbender

    jnbbender

    Joined:
    May 25, 2017
    Posts:
    487
    I am using the First person view and was wondering if there was any way to mimic a head bob while walking?
     
  46. JanOtt

    JanOtt

    Joined:
    Apr 23, 2019
    Posts:
    183
    Generally speaking, you'd have to generate a heab bob animation for the camera (either through Unity's built-in animation tools, an external program like Blender or procedurally creating it through code), then link that animation to the character's current state (for example, only play the head bob when the character is grounded and its movement speed exceeds a certain threshold).

    The controller component of 'Character Movement Fundmentals' offers two functions you can use for this purpose:
    • GetVelocity() -> Returns the character's current movement velocity.
    • IsGrounded() -> Returns 'true' if the character is currently grounded.
    You might also want to check out chapter 4.6 of the manual, which has a short code example on this as well.
     
  47. cmckelvy

    cmckelvy

    Joined:
    Nov 7, 2016
    Posts:
    12
    @JanOtt I'm loving the controllers. Great work.

    Just sharing a bit of today's work.

    The goal: I'm working on a test of some RPG mechanics in which the player can switch characters and/or possess other characters. So, I wanted to implement a system in which both the player and npcs use the mover system so the core movement mechanics are the same for both, so when you possess an NPC that was previously AI controlled, we just change the controller to one of the basic walker controllers. So, to make all entities use the mover system, I implemented a simple bridge script for controlling movers with NavMesh agents which will have their destinations set through behavior trees when not possessed by the player.

    Hierarchy:
    - The base Gameobject has all the character stats and the like and also includes the bridge component.
    - Navmesh Agent: This must be a separate sibling of the gameobject with the Mover component as the Navmesh agent and non-kinematic rigidbody will push eachother otherwise!
    - Controller: This Gameobject contains the modified controller, collider, rigidbody and Mover (Note: the Mover step and slope should be set equal to those of the NavMesh agent type used to keep them in sync).
    - Model: With smoothtransform component.
    Root: Mesh, animators, etc.
    So what I built first is the Bridge:

    Code (CSharp):
    1. public class NMAgentControllerBridge : MonoBehaviour
    2. {
    3.     [SerializeField]
    4.     Mover mover; //Mover component on the child
    5.     [SerializeField]
    6.     NavMeshAgent agent;//NavMeshAgent on the sibling of the child with the Mover component
    7.     [SerializeField]
    8.     float leash = 1f;//Acceptable distance between the NavmeshAgent and the Mover before the NavmeshAgent is stopped and waits for the Mover to catch up.
    9.  
    10.     bool hasAgent = false;
    11.     bool hasMover = false;
    12.  
    13.     private void Awake()
    14.     {
    15.         if (agent == null)
    16.         {
    17.             agent = GetComponentInChildren<NavMeshAgent>();
    18.         }
    19.         if (mover == null)
    20.         {
    21.             mover = GetComponentInChildren<Mover>();
    22.         }
    23.  
    24.         if(agent == null)
    25.         { hasAgent = false; }
    26.         else
    27.         { hasAgent = true; }
    28.  
    29.         if(mover == null)
    30.         {
    31.             hasMover = false;
    32.         }
    33.         else
    34.         { hasMover = true; }
    35.     }
    36.  
    37.     private void Update()
    38.     {
    39.         if(!hasAgent || !hasMover)//If we're missing and agent or mover, we return to avoid null reference errors.
    40.         { return; }
    41.  
    42.         if(agent.pathPending)//Don't do anything if the agent is calculating a path
    43.         {
    44.             return;
    45.         }
    46.  
    47.         if(agent.hasPath)
    48.         {
    49. [INDENT][INDENT]//If the distance between the simulated position of the agent on the x and z axis (agent.nextposition) and Mover position is greater than the length of the leash, stop the NavmeshAgent. When the Mover catches up, let the NavMeshAgent resume along the path.[/INDENT][/INDENT]
    50.  
    51.             if(Vector3.Distance(new Vector3(agent.nextPosition.x, 0f, agent.nextPosition.z), new Vector3(mover.transform.position.x, 0f, mover.transform.position.z)) > leash)
    52.             {
    53.                 agent.isStopped = true;
    54.             }
    55.             else
    56.             {
    57.                 agent.isStopped = false;//Resume
    58.             }
    59.  
    60.         }
    61.     }
    62. }
    Then, on the child that contains the Mover component (sibling of the NavMeshAgent), I put this Controller:

    Code (CSharp):
    1. public class AIWalkerController : BasicWalkerController
    2. {
    3.  
    4.     public NavMeshAgent agent;
    5.     bool hasAgent = false;
    6.     [SerializeField]
    7.     float leash = 1f;
    8.  
    9.     protected override void Setup()
    10.     {
    11.         base.Setup();
    12.         if(agent == null)
    13.         {
    14.             GameObject parent = transform.parent.gameObject;
    15.             agent = parent.GetComponentInChildren<NavMeshAgent>();
    16.         }
    17.         else { hasAgent = true; }
    18.  
    19.         if (!hasAgent)
    20.         {
    21.             if (agent == null)
    22.             {
    23.                 hasAgent = false;
    24.             }
    25.             else { hasAgent = true; }
    26.         }
    27.  
    28.         if(hasAgent)
    29.         {
    30.  
    31.             agent.updatePosition = false;
    32.             agent.updateRotation = false;
    33.         }
    34.     }
    35.  
    36.     protected override Vector3 CalculateMovementDirection()
    37.     {
    38.         Vector3 _movementDirection = Vector3.zero;
    39.         bool isMoving = false;
    40.  
    41.          if(!hasAgent)
    42.         {
    43.             return _movementDirection;
    44.         }
    45.  
    46.  
    47.         if(agent.hasPath && agent.remainingDistance > agent.stoppingDistance)
    48.         {
    49.             isMoving = true;
    50.         }
    51.  
    52. //If the NavMeshAgent is Moving, the Movement Vector to send to the Mover component is the vector from the our Transform position to the agent's simulated position.
    53.  
    54.         if(isMoving)
    55.         {
    56.  
    57.             var heading = agent.nextPosition - transform.position;
    58.             _movementDirection = heading.normalized;
    59.        
    60.         }
    61.  
    62.         return _movementDirection;
    63.     }
    64. //May implement jumping later
    65.     protected override bool IsJumpKeyPressed()
    66.     {
    67.         return false;
    68.     }
    69. }
    Navmesh Agent setup: For optimal results, I set the the Navmesh agent's speed to about double the Mover's speed (so the Mover will never be ahead of the agent) and the agent's acceleration to the movement speed (so it won't jitter when it stop and resumes waiting for the Mover).

    Now the Mover follows smoothly behind the NavMeshAgent (keeping the leash short has the Mover follow closely as the agent avoids obstacles). If anyone else is looking for something similar, I hope it helps. Thanks again for the great system!
     
    mattydidsomething and RogDolos like this.
  48. dock

    dock

    Joined:
    Jan 2, 2008
    Posts:
    605
    @JanOtt Great work on the Character Controller package. Really impressed with the general feel and how robust it is. I've been using it for a few weeks and keep running into some issues I was hoping you could help me with.

    In general I'm having a lot of problems with manual overrides, like wanting to control the camera rotation manually or
    move the character in scripting.

    Is it possible to change the facing direction of the character without it being overriden by the previous velocity? I am using topdown with 'TurnTowardControllerVelocity' but sometimes I just want to teleport the character to a new location and rotation.

    Using the top-down control, is there any way to manually tween the camera rotation between different rotations? I explicitly want to rotate 45 degrees at a time to look around, but I couldn't figure out a way to make the camera rotate smoothly without it fighting the controls.

    Finally, I'd love to see some 'hold jump to jump higher' control options.
    Thanks for the great work. I'm looking forward to the next update.
     
  49. JanOtt

    JanOtt

    Joined:
    Apr 23, 2019
    Posts:
    183
    Hi @dock!
    The easiest way to implement something like this would be to add add a simple function to the 'TurnTowardControllerVelocity' script that you can call to manually set the characters' rotation, whenever you want to teleport.

    The specifics depend a bit on your individual game though, so it'd probably be best if you contacted me via the support mail (support@j-ott.com) with a more-detailed description of how your teleportation works and I'll try my best to help!
    With a bit of custom code, that's definitely possible! There's just a few things to consider here first, though:

    Do you want the player to only be able to rotate the camera in 45° increments, or should these 45° rotations happen on top of the normal camera rotation? And do you need the camera angle to "snap" to certain angles (0, 45, 90, 135, 180 ...)?

    Just like before, please feel free to contact me via the support mail with more details and I'm sure we'll find a good solution!
    Thanks! A 'hold to jump higher' option is actually part of the next update. I just have a few minor code improvements to do, but after that, the update should be released shortly.
     
  50. MrJohnWeez

    MrJohnWeez

    Joined:
    Aug 31, 2013
    Posts:
    11
    If you try to edit certain prefabs with unity 2019.2.5 and have the root of the prefab with the mover component selected, the prefab will try to save 10 times per second!

    I found a fix for it.

    Go into the MoverInspector.cs Editor script and change the last line to this:
    Code (CSharp):
    1. //EditorUtility.SetDirty(mover);
    2. Undo.RecordObject(mover,"mover updated");