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

[Released] Kinematic Character Controller

Discussion in 'Assets and Asset Store' started by PhilSA, Sep 29, 2017.

  1. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    1,926
    Since it's been a while since the last update on the store, and since I've received tons of feedback recently, I've updated the original post with my current progress on things. See the "Here is my current task list for improvements and fixes" and "Longer Term Goals" sections

    Networking Example is taking longer than I originally expected, and I apologize for that. It's just that there were a bunch of fixes and features that made more sense to prioritize first, and I haven't had as much time as I would've wanted to actually work on this. But rest assured that it's still coming in the relatively short term (I'd say a few weeks / a month)
     
    Last edited: Dec 17, 2017
    thestrandedmoose likes this.
  2. nxrighthere

    nxrighthere

    Joined:
    Mar 2, 2014
    Posts:
    567
    @PhilSA After some additional tests, I realized that I solved the problem with jumps up the slopes, but got another one.

    Code (csharp):
    1. currentVelocity += (jumpDirection * jumpSpeed) - Vector3.Project(currentVelocity * jumpSupression, KinematicCharacterMotor.CharacterUp);
    With this code, I got the result I wanted, but now when the character jumps off the slopes he gets a noticeable velocity acceleration.

    [Link removed]

    I tried to do this without the Vector3.Project function and I went back to the result I started with, but the character's velocity is fine when he jumps off the slopes.

    [Link removed]

    Any idea how to prevent jumping so high up the slopes and prevent velocity acceleration when jumping off the slopes?
     
    Last edited: Dec 30, 2017
  3. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    1,926
    Since the control of the character's velocity is entirely in your hands, there wouldn't be any problems with this. (unless your spring is an actual rigidbody that "pushes" other rigidbodies upwards through actual motion)

    I think the thing you saw about springs was referring to attaching the character controller to spring joints (like ragdoll joints) and having its movement constrained by that. This is a thing that wouldn't work because this character, just like the built-in one, is kinematic, so it doesn't respond normally to all physics

    Right now, in the example character controller, I explicitly tell it to rotate towards camera direction at all times. But simply removing the line(s) that do this will result in what you want
     
    Last edited: Dec 17, 2017
  4. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    1,926
    You could try to check if the velocity is going upward or downward:
    Code (CSharp):
    1. bool goingUpward = Vector3.Dot(currentVelocity, KinematicCharacterMotor.CharacterUp) > 0f;
    if you're going upward, do your suppression code, and if not, do the regular code (...or maybe I got that backwards, but it's something like that)
     
  5. nxrighthere

    nxrighthere

    Joined:
    Mar 2, 2014
    Posts:
    567
    Oh, thank you again! Now it works fine.
     
  6. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    1,926
    Ah, yes. This'll be fixed in the next update. I basically just forgot to put something in UpdateRotation (it would more or less be the same thing as what's in there for regular movement)

    Right now the ExamplePlayer tells the ExampleCharacterController to orient itself towards the flattened camera direction via the ExampleCharacterController.SetInputs() method (look for where it is used in ExamplePlayer)

    If, instead, you want it to orient itself towards its move direction, and only do so when actually moving, you'd have to:
    1. When ExamplePlayer calls "Character.SetInputs()", pas the "cameraOrientedInput" as second argument too.

      This means "move towards cameraOrientedInput direction, and orient yourself towards that too"
    2. Now we'll make a change to the ExampleCharacterController.SetInputs() method to allow for zero lookInput vectors (when we're not actually moving):

    3. And finally, we need a small correction in ExampleCharacterController.UpdateRotation, which I just noticed while testing. In the Slerp, the first argument needs to be the CharacterForward:
     
    Last edited: Dec 17, 2017
  7. thestrandedmoose

    thestrandedmoose

    Joined:
    Jul 21, 2015
    Posts:
    70
    Hey Phil!

    I had an issue with the camera maybe you could help out with... So I've got a button that let's my player phase through objects- like walls and cages.

    The issue I'm getting is, if my character turns opaque/solid again while he's inside the cage, the camera snaps from it's normal position to be inside the cage with the player...

    Is there a way to make the camera ignore certain colliders? Or is this happening because of something in the character controller script? Not quite sure why it's occurring
     
  8. dadude123

    dadude123

    Joined:
    Feb 26, 2014
    Posts:
    789
    I don't think this has anything to do with the character controller.

    Try this:
    Set the camera (or rather the object that has the collider, could be the camera itself or a parent) to be on a new "camera" layer you create for it.

    Then go to the physics project settings and in the collision matrix find the intersection between "default" and "camera". (this thing: https://docs.unity3d.com/560/Documentation/uploads/Main/LayerBasedCollision.png )
     
    thestrandedmoose likes this.
  9. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    1,926
    Aside from dadude's solution, the OrbitCamera also has an array of IgnoredColliders that can be set via script
     
    thestrandedmoose likes this.
  10. thestrandedmoose

    thestrandedmoose

    Joined:
    Jul 21, 2015
    Posts:
    70
    Thanks! I don't see the array in my inspector but I do see the obstruction layers dropdown. May just use that instead. Idk how I missed it before, I think I was looking for "Ignore Colliders" oops

    Thanks guys!
     
  11. flyingaudio

    flyingaudio

    Joined:
    Dec 3, 2010
    Posts:
    98
    Yes, the jitter is like the bug you referred to.
    Where does that leave us? It seems like Unity's stance is, we hope Physx3.4 will fix it when it gets added. But this is a major issue that they should be actively repairing ASAP.
     
  12. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    1,926
    Yeah, I think it's extremely bizarre that this isn't considered to be a major issue by Unity.

    But... for the time being, there is a hacky way around it. You can:
    • Deactivate interpolation on your rigidbody (to deactivate it in KinematicCharacterController, go set the "UseInterpolation" constant to false in the code of KinematicCharacterSystem)
    • place a transform as a child of the rigidbody
    • Place all of your meshes or visual elements on/under that child
    • Write your own interpolation code to make that transform follow the rigidbody smoothly
    It's an unsatisfying fix, but it'll work and it'll give you the same results
     
    Last edited: Dec 18, 2017
  13. flyingaudio

    flyingaudio

    Joined:
    Dec 3, 2010
    Posts:
    98
    Thanks for the suggestion. If this doesn't take care of it, I will need to check if another engine can do this properly.
     
  14. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    1,926
    Oh, and, there's also another easier alternative, if it suits your project:
    • Set a framerate cap using Application.targetFramerate (let's say 120 fps, for this example)
    • Disable interpolation as explained above
    • Set your fixedTimeStep to match your maximum framerate. So in this case, you'd set it to (1/120) = 0.0083
    This basically guarantees that your physics will always be updated at least as fast as your framerate. If your game isn't too physics-heavy, it can be an option
     
  15. flyingaudio

    flyingaudio

    Joined:
    Dec 3, 2010
    Posts:
    98
    @PhilSA: It would be interesting to test, but framerate can't be guaranteed, so I would expect hitches to show up sometimes. I have also tried triggering the simulation myself, so it is in timestep with the render loop, but I still get hitches.
     
  16. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    1,926
    To counter the Unity interpolation bug in 2017.2 and 2017.3, I've decided I will ship a "Custom" interpolation method with the next update. People will be able to choose it, along with "None" and "UnityRigidbody". It'll only affect characters and PhysicsMovers, but you can copy it if you need it for other things. Also, it does not use a child transform to interpolate, unlike what I explained above

    I've already got it working, and the cost of it is about 0.06 ms for 200 characters in a build. In other words; it's almost nothing. It may even compensate exactly for the time we gain by not letting Unity handle interpolation. More tests are needed to make sure this works with every possible physics configuration (autoSyncTransforms, etc....), but I'm fairly confident about it.

    ------

    Here's a little warning, though; due to all of the changes that this new interpolation system, the new step-handling, the ledge hits, the networking, etc.... have entailed, the next update will be a pretty big one. Thankfully, the changes mostly just affect the internal workings of KinematicCharacterMotor and KinematicCharacterSystem, so your custom character controllers will not be affected and they'll still work. However, I know some of you have modified KinematicCharacterMotor, and sadly I don't think there will be any way to convert to the new version easily. The changes are so widespread that even a diff won't help. It's unfortunate, but I feel that it's better to do this while the project is still in its infancy than to have it constrain us forever
     
    Last edited: Dec 19, 2017
  17. flyingaudio

    flyingaudio

    Joined:
    Dec 3, 2010
    Posts:
    98
    @PhilSA: Awesome, can I test your new version now? We are in the middle of this, and instead of doing more experimenting I would rather test yours and give you feedback.
     
  18. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    1,926
    sure, I'll PM you the work-in-progress version (I think everything is fine, but no guarantees)
     
  19. nxrighthere

    nxrighthere

    Joined:
    Mar 2, 2014
    Posts:
    567
    @PhilSA Tiny suggestion to hide the KinematicCharacterSystem object in the scene hierarchy since it doesn't contain any information for the developer. :rolleyes:
    Code (csharp):
    1. systemGameObject.hideFlags = HideFlags.NotEditable | HideFlags.HideInHierarchy;
    2.  _instance.hideFlags = HideFlags.NotEditable | HideFlags.HideInHierarchy;
     
  20. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    1,926
    I'm unsure about this one. In the past, I have seen the horrors that could be caused by hidden stuff the the users didn't know about. For example, imagine a situation where we move characters to an additive scene, and then unload the previous one. We will have lost the KinematicCharacterSystem and we won't really understand why everything stopped moving
     
  21. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    1,926
    This is probably because I should be remembering a "lastSeenPosition" whenever the player moves off of the navmesh. I'll remember this for next update
     
  22. flyingaudio

    flyingaudio

    Joined:
    Dec 3, 2010
    Posts:
    98
    Outstanding work @PhilSA. You have really gone the extra mile as an asset developer. Thank you.
     
  23. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    1,926
    So the wall-jumping mechanic needs to know two things:
    1. _canWallJump: can we wallJump right now?
    2. _wallJumpNormal: in which direction will the jump be?
    And these two things need to be set right before we start checking for "if(_canWallJump ......)") in UpdateVelocity. So the strategy I would suggest here goes like this:
    1. Set your capsule radius to something that a bit inflated compared to its regular size. Like 0.1f wider for example (use KinematicCharacterMotor.SetCapsuleDimensionsAuto() for this)
    2. Do an OverlapCapsule with those capsule dimensions to see if any colliders are touched
    3. if so,
      1. Do a ComputePenetration between your character capsule and the first overlapped collider
        1. If the above step returned true, set _canWallJump to true, and set _wallJumpNormal to the returned normal of the ComputePenetration
    4. Set your capsule radius back to its regular size using KinematicCharacterMotor.SetCapsuleDimensionsAuto()

    For clarification, all of this would be done in UpdateVelocity(). Doesn't matter at which point it is done, as long as it's before the jump handling part

    You can play with the "AirAccelerationSpeed" value for that. Maybe even set it to zero via script only if you've wall-jumped
     
  24. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    So what is the correct way to disable/enable the character controller? Just disabling KinematicCharacterMotor doesn't seem to do it.

    I'm completely physics bound and a lot of that is from a case where the character isn't moving anyways, so just disabling the controller is a big win in cpu usage.
     
  25. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    1,926
    You can do that by calling HandlePhysics(false, false), and then HandleMovement(false) on the KinematicCharacterMotor

    HandlePhysics() controls the activation of collision-solving and the actual capsule, wheras HandleMovement() controls the activation of velocity-handling

    But now that you mention it, I should probably add a SetActive(bool) that does all this at once

    Edit: actually... you can probably disable both the script and the collider, and that'll work
     
  26. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    So really strange. HandlePhysics(false,false), disable controller, disable collider. Event added logic to KinematicCharacterController to return on every update phase if not enabled.

    The character gets parented to the moving platform. So one non kinematic rigidbody parented to another. The really strange thing is there is some interaction there. But it's like for every unit the platform moves, the child moves like a tenth or less.

    correction those are kinematic rigidbodies
     
    Last edited: Dec 21, 2017
  27. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    So the simplest way to solve this was just remove the rigidbody in addition to disabling the controller. Save off it's config then add a new rigidbody with the same config when enabling.
     
  28. sharksharkshark

    sharksharkshark

    Joined:
    Apr 27, 2015
    Posts:
    13

    Would you have any idea for an ETA of this update in the Asset Store? We are pretty dang close to pulling the trigger on this asset but this new regression in 2017.2+ has been making us hesitant. I've been very impressed with your support in this thread and the amount of thought you've put into this controller, so hopefully we can give you our money soon ;).
     
  29. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    1,926
    There's gotta be a better way to do this than that. I'l make sure to have something to handle this cleanly on next update

    Actual scaling is not allowed, because we save a lot on performance by always assuming our character capsule object's scale is (1,1,1). However, there is still a way to accomplish what you want:
    1. Scale the child object of the character (the one that contains the mesh)
    2. Use KinematicCharacterMotor.SetCapsuleDimensionsAuto() to reduce the size of the capsule by the same factor
    You could make it rotate towards the _wallJumpNormal that you got at the moment of wall-jumping. Just store it somewhere and use it in UpdateRotation instead of the regular input direction. You can revert to the regular rotation-handling code once you've landed

    My estimate would be mid-january. If I'm not done with everything by that time, I'll just shelve all the WIP stuff I'm working on and do an update with what I have so far (including the interpolation system).

    However, I discovered yesterday that while it does work perfectly with characters and moving platforms (kinematic rigidbodies), it will not be possible to copy this and apply it to non-kinematic rigidbodies as I suggested, so that's a limitation to be aware of. It just messes with collisions too much. Maybe there'd be a way to make this work fine by turning off Physics.autoSimulation and getting explicit control over the physics loop, but this is starting to sound too complex/unmanageable for an asset store product

    I still think it's almost unthinkable that this interpolation problem never actually gets fixed. I'll keep re-reminding the devs of the gravity of this issue as soon as the 2018.1 beta forum appears. Perhaps they don't yet realize that this nearly invalidates Unity as a 3D game engine, but I'll make sure to explain it to them very clearly
     
    Last edited: Dec 22, 2017
  30. thestrandedmoose

    thestrandedmoose

    Joined:
    Jul 21, 2015
    Posts:
    70
    Hey Phil,
    Is there an easy way to play an audioclip when the character controller hits ground? (Like landing sound after a jump)?
    Just wanted to check before I build my own solution
     
  31. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    1,926
    There is a part about detecting landing in the walkthrough. This would give you a hook to call your clip from
     
    thestrandedmoose likes this.
  32. thestrandedmoose

    thestrandedmoose

    Joined:
    Jul 21, 2015
    Posts:
    70
    Thanks! I'll look it up
     
  33. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    1,926
    it should be something like this:
    Code (CSharp):
    1. currentRotation = Quaternion.LookRotation(Vector3.ProjectOnPlane(_wallJumpNormal, KinematicCharacterMotor.CharacterUp).normalized, KinematicCharacterMotor.CharacterUp);
    Notice the "ProjectOnPlane" part. This is what would prevent it from tilting. You might also want to make the rotation smooth and not direct. To do this, you can copy what is already done with the "Slerp" just beforesetting the currentRotation

    For this you can use the "ObstructionLayers" on the camera, which determine what it can collide with
     
  34. davidseth8

    davidseth8

    Joined:
    May 8, 2016
    Posts:
    13
    @PhilSA Have you had further thoughts on the Mecanim vs. Playables API approach? I'm very keen on your thoughts here and additional code/pointers on integrating character animation into your framework.

    I'm enjoying my purchase as well as the lessons from your walkthrough.
     
  35. nxrighthere

    nxrighthere

    Joined:
    Mar 2, 2014
    Posts:
    567
    @davidseth8 I use Playables in my game with this controller. In my opinion, Playables are much more flexible and convenient than Mecanim. Instead of a headache with Mecanim's nodes, I use a simple component that gets different animation states from the character controller, and it works great.

     
    Last edited: Dec 22, 2017
    davidseth8 likes this.
  36. davidseth8

    davidseth8

    Joined:
    May 8, 2016
    Posts:
    13
    @nxrighthere Thanks for that. Is this a script that you wrote or that you got from somewhere? I'm new to the Playables API so looking for a place to start. Could you recommend some resources or links?
     
  37. nxrighthere

    nxrighthere

    Joined:
    Mar 2, 2014
    Posts:
    567
    davidseth8 likes this.
  38. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    1,926
    I've used Playables API to handle all animations in the context of a real project, and it was a true revelation. The project needed some pretty complex animation tasks, such as "warping" the middle part of a "jump-and-grab-ledge" animation so that the animation could fit to any jump height, and the Playables API allowed me to do this very easily. There were also dozens of misc animations required for several different actors, all of which could have their speed modified by different character attributes, and the Playables API made it easy to modify anim graphs on-demand at runtime instead of placing everything in advance by hand. It would've been a complete nightmare to do these things with mecanim. I don't think I'll ever really use Mecanim again unless I really have to

    The code-based workflow gives you a lot more power than node-based.

    As for integrating the animation with the character controller, it could be done in any way you want, really. Have an animation handler that observes the character class and chooses animations based on velocities, input events, etc, etc....
     
    Last edited: Dec 23, 2017
    davidseth8 likes this.
  39. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    1,926
    To do this, the ExamplePlayer class would need to send inputs to the camera that would make it rotate towards the character direction. (via the OrbitCamera.SetInputs() method)

    The OrbitCamera class in its current state is maybe not perfectly equipped for this, because it takes displacement as input instead of an actual direction. It can still do what you're asking, but it won't be as perfect as if it worked with directions. Once all of the current WIP features are done, I will think about revamping the "Example" classes so that they support more common cases, such as this one or having the character face the moving direction
     
    Last edited: Dec 23, 2017
  40. Jdfskitz

    Jdfskitz

    Joined:
    Oct 31, 2012
    Posts:
    7
    Hi, just wanted to say I'm still using your character controller and it's doing great :) I'm still learning about it, but it's definitely able to achieve everything I want. I've been working on artistic accommodations towards my game but it's coming along!

    https://www.smdstudios.com if you ever want to use something as an example I would gladly be willing to share. But I'm just here to say thank you for such an amazing plugin.
     
    PhilSA likes this.
  41. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    1,926
    Sounds like a perfect job for cinemachine. Ive seen people make great 3rd person cams with it
     
  42. Teh_Lemon

    Teh_Lemon

    Joined:
    May 12, 2015
    Posts:
    17
    Hi. I'd like to simplify my code by always assuming the up vector for my character and camera to be 0,1,0. Would I run into any problems using your controller? (e.g ramps)
     
  43. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    1,926
    There wouldn't be any problems with this. At a high level, the way that this controller works is that you tell it what its velocity (Vector3) and rotation (Quaternion) should be at all times, so having a fixed up direction is simply a question of never assigning a rotation that doesn't point upwards
     
  44. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    1,926
    The most obvious optimizations are the ones under "Quality & Optimizations" in the motor inspector. Removing any of these things will give you significant performance improvements:
    • Step & ledge handling can be removed if you're willing to replace steps with ramp colliders in your level. But keep in mind this will also remove handling of things like "MaxStableOnLedgeVelocity", etc.... since both step handling and ledge handling use the exact same two raycasts to determine these things. It's a way to hit two birds with one stone.
    • InteractiveRigidbodyHandling can be turned off if you don't need any moving platforms handling or the ability to stand on a dynamic rigidbody
    • Lots of games can get away without "safe movement" (read the tooltip for a description). If you want to understand where safe movement comes in handy, try turning it off and running/strafing into the angled corridors in the CharacterPlayground scene. You'll go right through

    You can also remove interpolation by setting the "useInterpolation" constant directly in the KinematicCharacterSystem code. Unity physics by default run at 50 fps. If your game never runs at more than 50 fps (which might be the case on mobile), then interpolation is just completely useless overhead

    And finally, if you're really motivated, you can remove the notion of rotation from the motor entirely (comment out everything related to CharacterController.UpdateRotation, CharacterRigidbody.rotation and CharacterRigidbody.MoveRotation and in KinematicCharacterMotor.cs). When you think about it, the actual rigidbody never needs to rotate if the character always stays upright; only the visuals/mesh need to rotate. But that optimization is probably not worth it unless you have 100+ characters active
     
    Last edited: Dec 26, 2017
  45. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    So I'm working on a kinematic vehicle controller for my game and had an idea that you might have possibly explored already yourself, maybe save me some time if you know reasons why it wouldn't work.

    Currently I'm using Physics.OverlapSphereNonAlloc and then Computepenetration much in the same way you are. But calling those every FixedUpdate gets expensive. So I was thinking about using a kdtree or spatial hash to track positions of rigidbodies.

    So if no rigidbodies are in contact range you avoid those two calls completely. And if they are in contact range I was thinking filter those even futher using ClosestPointOnBounds to determine which ones are intersecting, then finally ComputePenetration.
     
  46. owlyoop

    owlyoop

    Joined:
    Jun 12, 2017
    Posts:
    2
    This looks awesome! I'm gonna buy this if any of my projects gets far along

    I'm trying to write my own fps character controller, but I have had problems with slopes. I got moving down slopes working but haven't had any luck with my character being able to jump while moving down slopes. I'm wondering how you solved that problem because the demo feels very solid. I also have some janky solution to slopes that are above the slope limit but this version is way better.
     
  47. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    1,926
    Would be interesting to see performance comparisons with this approach. I'm unsure of if a ClosestPointOnBounds is actually much less costly than a simple Overlap

    Essentially, there is a notion of being "snapped to ground" in my controller, which means the controller keeps casting downwards and moving to be snapped directly to the closest surface. When jumping, it is necessary to call "ForceUnground", which will prevent the snapping from happening until the next time we land on a proper surface
     
  48. thestrandedmoose

    thestrandedmoose

    Joined:
    Jul 21, 2015
    Posts:
    70
    Hi Phil,

    So I currently have a script that kills and respawns my character:


    Code (CSharp):
    1. void OnTriggerEnter (Collider other)
    2.     {
    3.         StartCoroutine (RespawnDelay ());
    4.     }
    5.        
    6. IEnumerator RespawnDelay ()
    7.     {
    8.         ExampleCharacterController.SetActive (false);
    9.         Debug.Log ("dead");
    10.         yield return new WaitForSeconds (5);
    11.         ExampleCharacterController.transform.position = respawnPoint.transform.position;
    12.         Debug.Log ("respawn");
    13.         ExampleCharacterController.SetActive (true);
    14.     }
    The problem is, when I set my character controller back to active, it still has the same velocity as when the character controller was disabled.
    How can I reset the character controller velocity to 0 in another script? I assumed it would be something like:
    ExampleCharacterController.GetComponent<ExampleCharacterController>().UpdateVelocity(Vector3.zero, 0.0f);
    but that's not working. Sorry I'm pretty new to coding so this is all a learning experience for me
     
  49. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    1,926
    You can do this by setting the KinematicCharacterMotor.BaseVelocity to Vector3.zero.

    Here's an explanation for the velocities of the character:
    • BaseVelocity is the velocity of the character resulting from movement
    • StableInteractiveRigidbodyVelocity is the velocity resulting from standing on moving platforms
    • Velocity is the sum of the above two velocities
    It's important to have these velocities separate for all sorts of reasons, but most notably:
    1. It's useful for animation. If your character is standing still on a moving platform that moves at 10 m/s, his "Velocity" and "StableInteractiveRigidbodyVelocity" will be 10, but his "BaseVelocity" will be 0. For driving a locomotion animation, you would want to use only the "BaseVelocity" in this scenario.
    2. Velocity from moving platforms must be absolute (not smoothed out in any way). Therefore, it has to be calculated separately
     
    thestrandedmoose likes this.
  50. thestrandedmoose

    thestrandedmoose

    Joined:
    Jul 21, 2015
    Posts:
    70
    So I tried this, but it's telling me that KinematicCharacterMotor.BaseVelocity is read only:
    ExampleCharacterController.GetComponent<KinematicCharacterMotor>().BaseVelocity = Vector3.zero;