Search Unity

  1. Looking for a job or to hire someone for a project? Check out the re-opened job forums.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

[Released] Kinematic Character Controller

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

  1. rtargosz

    rtargosz

    Joined:
    Aug 22, 2012
    Posts:
    17
    I have now switched to event driven input handling with no input update loop and it is amazingly fast:
     
  2. billnguyenme

    billnguyenme

    Joined:
    Dec 5, 2020
    Posts:
    51
    Would you mind sharing the commands/codes used to implement into the original scripts? This is mainly for the active commands such as Jumping.
     
  3. LezTusi

    LezTusi

    Joined:
    Nov 15, 2014
    Posts:
    51
    Does anyone know how do Animator's Target Matching with KCC?
    SetPosition and SetRotation works, but I honestly think the built-in Target Matching works better.
     
  4. rtargosz

    rtargosz

    Joined:
    Aug 22, 2012
    Posts:
    17
    I've dropped my 3 modified files for the input, camera and controller into a public Github repo here: https://github.com/rtargosz/BentVectorShared. This is still very much a WIP, but gives you some idea how to modify the example code from Philippe to use the new Input System package with KCC driven by events. My player is restricted to movement in the Z/Y access: left-right movement with A/D keys and jump with W, crouch with S. Player can interact with SPACE and fire with E/Left Control. Camera is controlled by a Cinemachine to facilitate cut-scenes, so there's no camera controller code.
     
  5. billnguyenme

    billnguyenme

    Joined:
    Dec 5, 2020
    Posts:
    51
    Thanks for the github link! I managed to switch over to the new input system after some trial and error using a different way. I think you're way is better than mine since it doesn't have to check for the jump trigger every frame so I'll use it as a reference.

    Example of what I did:
    playerInputActions.Movement.Movement.performed += x => input_Movement = x.ReadValue<Vector2>();
    playerInputActions.Movement.View.performed += x => input_View = x.ReadValue<Vector2>();


    My next goal is to figure out how to incorporate ledge hanging into this controller.
     
  6. URnewby

    URnewby

    Joined:
    Oct 2, 2018
    Posts:
    1
    I really like this controller but am having trouble with a Pause Menu. The Pause Menu works fine until I add your character controller. The buttons on the menu panel won't highlight and cannot be clicked.
    I have tried setting Time.timeScale=0f; Still doesn't work.
    Disabled all scripts. Still no worky.
    Disabled Audiolistener. Still no luck.
    Rick
     
  7. neo-mashiro

    neo-mashiro

    Joined:
    Aug 7, 2020
    Posts:
    16
    Does anyone know how to robustly detect if the character leaves off the ground? I need to know when the character gets into the air in order to play an airborne animation.

    Code (CSharp):
    1. bool inTheAir = !motor.GroundingStatus.IsStableOnGround;
    2. bool inTheAir = !motor.GroundingStatus.IsStableOnGround && motor.LastGroundingStatus.IsStableOnGround;
    For simple scenarios such as jumping or falling off the platform, the code above gets the job done. However, I found that this will also be triggered when the character tries to move up a steep slope that it cannot step onto.
     
  8. bluescrn

    bluescrn

    Joined:
    Feb 25, 2013
    Posts:
    545
    Hi,

    Is there a way to prevent the character 'tightrope walking' along a collision edge, like this case with an almost-vertical plane? It seems possible to jump and land on these edges regardless of whether they're in a stable layer or not.

    tightrope.png

    I'm looking for a way to create colliders for scenery objects that the player will always slide off.

    (Also, I seem able to jump onto 'non-stable' slopes but the character doesn't slide down them - Is that normal? or a setup issue or bug?)
     
  9. billnguyenme

    billnguyenme

    Joined:
    Dec 5, 2020
    Posts:
    51
    Has anyone managed to add in a lock on system? There isn't any documentation for it and I can't seem to get it to work. I'm simply trying to have the player's rotation orient towards the target.
     
  10. topitsky

    topitsky

    Joined:
    Jan 12, 2016
    Posts:
    22
    Anyway to skip the simulation for couple of frames? I have system which freezes animation upon hit, and Id like the motor to do that too.
     
  11. Zebbi

    Zebbi

    Joined:
    Jan 17, 2017
    Posts:
    493
    Was this ever taken any further? I'm wondering if this could be used to simulate a box collider (Quake-style):
     
  12. Zebbi

    Zebbi

    Joined:
    Jan 17, 2017
    Posts:
    493
    PS: why has PhilSA not posted here since Apr 24, 2020?
     
  13. Gooren

    Gooren

    Joined:
    Nov 20, 2015
    Posts:
    251
    He doesn't reply here much. I always had better luck when contacting him by e-mail.
     
  14. BenniKo

    BenniKo

    Joined:
    Mar 24, 2015
    Posts:
    19
    Whats the correct way to rest your character?
    For example when your player dies and you reset his position.
    It seems I have to (at least) also reset the velocity?
    Anything else?
     
  15. Vincent13122

    Vincent13122

    Joined:
    Oct 26, 2014
    Posts:
    82
  16. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    26,892
    There should be no performance difference. Do you mean fast to set up?
     
  17. Flavelius

    Flavelius

    Joined:
    Jul 8, 2012
    Posts:
    811
    @PhilSA
    When the KinematicCharacterMotor is part of a prefab, it's impossible to remove (without modifying the source code) as the 'Remove Component' menu action, which seems to be custom, doesn't set the internals dirty, so the save button of the prefab mode doesn't become active.
    The solution is to replace the normal destroy calls with the undo equivalent
     
    Last edited: Feb 20, 2021
  18. simpa975

    simpa975

    Joined:
    Feb 15, 2019
    Posts:
    3
    Try to use "!motor.GroundingStatus.FoundAnyGround" instead. When the motor detects an unstable surface "IsStableOnGround" will return false, a steep slope counts as an unstable surface.
     
    neo-mashiro likes this.
  19. BenniKo

    BenniKo

    Joined:
    Mar 24, 2015
    Posts:
    19
  20. Vincent13122

    Vincent13122

    Joined:
    Oct 26, 2014
    Posts:
    82
    Whoops sorry I altered it over time, what I'm using now is:

    Code (CSharp):
    1. motor.enabled = false;
    2. motor.BaseVelocity = Vector3.zero;
    3. motor.AttachedRigidbodyVelocity = Vector3.zero;
    4. motor.SetCapsuleCollisionsActivation(false);
    And then to reenable it:
    Code (CSharp):
    1. motor.SetCapsuleCollisionsActivation(true);
    2. motor.enabled = true;
    3. motor.BaseVelocity = Vector3.zero;
    4. motor.AttachedRigidbodyVelocity = Vector3.zero;
    (You need to make AttachedRigidbodyVelocity public)
    Not sure if the order of these lines matters, but for some reason I wrote them like this lol
     
    Last edited: Mar 1, 2021
    BenniKo likes this.
  21. marccrobbins

    marccrobbins

    Joined:
    Nov 10, 2014
    Posts:
    2
    Have you ever tried to make an XR CharacterController with this? I recently attempted it with this package and the only issue I'm running into is the collision detection following my head(x, z).
     
  22. FcsVorfeed

    FcsVorfeed

    Joined:
    Aug 15, 2014
    Posts:
    37
    Still cannot access motor.AttachedRigidbodyVelocity
     
  23. Vincent13122

    Vincent13122

    Joined:
    Oct 26, 2014
    Posts:
    82
    Just make it public, keep in mind if you update the asset you'll have to set it to public again
     
  24. billnguyenme

    billnguyenme

    Joined:
    Dec 5, 2020
    Posts:
    51
    I'm curious about the purpose of this code, does it actually translate the velocity in the CharacterController over to rigidbody? If so, this is exactly what I'm looking for in my projectile prediction script which is based on Rigidbody velocity/
     
  25. simpa975

    simpa975

    Joined:
    Feb 15, 2019
    Posts:
    3
    I know this is a very late reply, but if you're still having this issue I found a solution.

    Jitter on objects following Cinemachine camera - Unity Forum

    All I did was to put my "rotate character mesh script" underneath the CinemachineBrain script in the Script Execution Order.
     
  26. simpa975

    simpa975

    Joined:
    Feb 15, 2019
    Posts:
    3
    I saw one of your older posts about Ledge detection, and I'm wondering if you got anywhere with that solution? The one where you used a downward raycast in front of the character. I'm also looking to simulate a box collider at the bottom, I've seen it implemented on other CC solutions and I've tried to use there approach on this one, without any success so far.
     
  27. ChainsawFilms

    ChainsawFilms

    Joined:
    May 28, 2016
    Posts:
    16
    I'm trying to set this up with SteamVR. I've a main gameobject, and two children; one the Character Controller, one the Camera Rig.

    How do I translate input from the Character Controller to the parent, effectively keeping the Character Controller centred on the Camera Rig headset?

    Thank you
     
  28. Zebbi

    Zebbi

    Joined:
    Jan 17, 2017
    Posts:
    493
    Yeah, I'm going to rewrite it soon, I'll post the final code eventually when it works. You're right, it could be used to create a box collider-type simulation for edges, but I'm not entirely sure how to override the built-in system with this.
     
unityunity