Search Unity

[Released] Kinematic Character Controller

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

  1. Zebbi

    Zebbi

    Joined:
    Jan 17, 2017
    Posts:
    521
    Interesting, I'm doing my ledge check with a forward ray that shoots forwards half a unit, then a ray that hits the ground below the player and the final third ray checks shoots slightly down from the y of the ground hit back towards to the player:


    It would be interesting to know if the ledge detection in KCC gives a similar result in regards to the ledge it detects, certainly if it would be similar enough to use for a projection.
     
  2. f0ff886f

    f0ff886f

    Joined:
    Nov 1, 2015
    Posts:
    201
    Hi Phil,

    I have run into an issue that I don't quite know how to fix.
    How would you actually affect the velocity of the KCC GameObject in this setup? If you rotate MyCharacter and only MyCharacter its like rotation a camera stuck inside a body, but the body needs to orient itself to the camera's forward vector, does it not?
     
  3. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    1,926
    I think your method of detecting ledges should be pretty good. The reason why I didn't use an approach like this built-into KCC is that this is an approximation, and there will be cases where it doesn't work in more complex scenarios.

    But since you coded this ledge detection yourself, you'll be able to adapt it if you find cases where it doesn't work, so you could totally stick to that. It does have the advantage of having a longer range than my method
     
    Zebbi likes this.
  4. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    1,926
    The KCC would know the rotation of the rotating child object, and calculate its velocity based on what the forward of the child object is

    Or alternatively, the camera rotates first, then the child object rotates to face the camera, then the kcc object calculates its velocity based on camera fwd, etc...
     
    Last edited: Apr 19, 2020
  5. yourcomputer

    yourcomputer

    Joined:
    Apr 28, 2017
    Posts:
    2
    Thank you, this is exactly how I ended up solving it and it works perfectly! :)

    This has quickly become my favorite asset.

    edit to go with the above post: The way I'm handling velocity is already by way of camera fwd so taking my rotation code from the KCC to the child object didn't even require me to rewrite any velocity handling code.
     
    Last edited: Apr 19, 2020
  6. f0ff886f

    f0ff886f

    Joined:
    Nov 1, 2015
    Posts:
    201
    I think I'm being dense here, sorry. The "traditional way" I used is to set the Character Rotation from code calculated in the Camera Controller with SetInputs() (along with the movement input vector). Inside SetInputs the target rotation is assigned to _lookInputVector, and the movement velocity is generated as well.

    To convert this case, I put all rotation logic in the Camera Controller (which we can refer to as MyCharacter GameObject from the above example), then how, where do you apply that to KCC as just a velocity? Or am I looking at this the entirely wrong way :D

    Sorry for the confusion, its specifically the "how will it know" part that's catching me up: "The KCC would know the rotation of the rotating child object".
     
  7. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    1,926
    So let's say your KCC character controller script has a reference to the camera transform, it could calculate its velocity in UpdateVelocity() like this:
    • Vector3 targetVelocity = Vector3.ProjectOnPlane(myCameraTransform.forward, motor.CharacterUp).normalized * moveSpeed;
    ...or it could keep a reference to the child object transform and do the same thing:
    • Vector3 targetVelocity = Vector3.ProjectOnPlane(rotatingChildTransform.forward, motor.CharacterUp).normalized * moveSpeed;
     
  8. Zebbi

    Zebbi

    Joined:
    Jan 17, 2017
    Posts:
    521
    Yeah, that's what I'm concerned about, cases where it might fail if there's gaps or weird mesh shapes. I find a corner by shooting a couple of similar extra rays either side rotated 20 and -20 degree angles and if they find a point that differs from the centre ray, it's a corner and I just force the Move() vector to 0,0,0 until the player rotates away from the corner (and we proceed with ProjectOnPlane until we rotate from the edge).



    It would be a huge relief if there was anything in KCC to make this work better for me, but if not, that's fine, this set-up would work just as well with KCC as it would with CC.
     
    Last edited: Apr 19, 2020
  9. Gooren

    Gooren

    Joined:
    Nov 20, 2015
    Posts:
    332
    I ended up using a configurable joint. This somewhat reduced (but not eliminated) the issue by introducing some springiness. I even tried disabling KCC Interpolation. That did not help. I also tried enabling interpolation on the held rigidbody. Also didn't help.
     
  10. rxmarccall

    rxmarccall

    Joined:
    Oct 13, 2011
    Posts:
    353
    @PhilSA
    I'm trying to cancel out my players velocities when it hits it's "head" on a ceiling.

    Currently inside of `OnMovementHit` I'm checking if the hitPoint is > the characters transform.position, but this feels like a weak solution. What would you suggest is the best way to determine if the character has hit his head on a ceiling?
     
  11. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    1,926
    My suggestion would be:
    if(Vector3.Dot(hitNormal, motor.CharacterUp) < 0f)
    {
    // hit on head
    }


    Blue represents character, and red represent the 2 hit normals in this context.

    Basically what the above formula detects is if the hit normal is going in a direction that is opposite to our character up. In the case of a capsule shape, this can only happen if the hit is on the upper demi-sphere of the capsule.

    Due to float errors, it is probably safer to go with "if(Vector3.Dot(hitNormal, motor.CharacterUp) < -0.1f)" though. The more that right side value is close to -1f, the more it'll only detect a "direct" head hit
     
  12. AdamSingle

    AdamSingle

    Joined:
    Apr 18, 2013
    Posts:
    22
    Good morning team. I've just bought this asset for a game I'm about to start on. I've always tried to do this type of controller manually and this looks like a huge asset for getting better results than I ever got.
    I have a couple of early questions if that's ok.
    My game mixes between parts that are very parkour movement flow (which I'm confident this asset can do) and something similar to snowboarding (in two very different areas of the world). My assumption is I'll handle the boarding quite differently, perhaps as something similar to a moving platform, except it uses physics to slide down hills. But the player isn't always on the board. They could just run across the hills. In that case I want to make sure they are slow going up, and somewhat sliding when going down (it's meant to be quite awkward).
    I was working through the walkthrough and I'm up to jumping and I notice there are some checks for being able to jump while sliding, but I didn't see my character sliding in the first couple of movement scenes. Did I miss something there? Will I have the control to slow the player when going up a slope and slide them when going down?
    I notice a lot of talk about Stable ground. But I haven't seen that explained much in the docs. Is that what I'm looking for? I feel like the slopes I'm talking about, for walking up and down, would ideally be described as not stable, but I'm not sure that means the same thing as what it means for the Kinematic Motor
     
  13. BrightBit

    BrightBit

    Joined:
    Jan 22, 2013
    Posts:
    265
    Hi all,

    I am currently experimenting with a simplified solar system that contains a single planet orbitting a sun. The orbit radius is 40.000 units. In order to avoid floating point issues, I have to reposition the planet, the sun and the player every now and then (currently every time the player is more than 10 units away from the origin).

    My problem is that I don't know where, when and how to do that. If I reposition the mentioned objects in a FixedUpdate call, the rigidbody of the planet seems to be one frame off because its sudden velocity change slingshots the Player into space.

    Can you give me directions?
     
  14. katsuragi545

    katsuragi545

    Joined:
    Jun 25, 2014
    Posts:
    38
    @PhilSA

    When dealing with multiple states, is it okay to transition to a different state at any time, or should transitions only occur in BeforeCharacterUpdate(), SetInputs(), and AfterCharacterUpdate()?

    For example, in my game I have a Default state and a PoleClimb state. When the player is climbing a pole in the PoleClimb state and decides to jump off the pole, they go into the Default state. After the jump (which occurs in UpdateVelocity()), should I immediately transition back to the Default state or should I keep track of the fact that I jumped, and use that in AfterCharacterUpdate() to then transition to the Default state?
     
    Alvarezmd90 likes this.
  15. transat

    transat

    Joined:
    May 5, 2018
    Posts:
    779
    Does anyone have any tips for connecting KCC to the new input system via a Player Input component? I’ve got keypresses working but for some reason movement is not working. Not yet sure if it’s an issue at my end or if it’s because I’m on 2020.2a / URP 8.10.

    Would love for someone to share some code with me if they have a similar set-up.
     
  16. Deozaan

    Deozaan

    Joined:
    Oct 27, 2010
    Posts:
    707
    I just bought this asset which says it's compatible with Unity 2018.4.13 and above. I imported it into a new/empty 2018.4.20f1 project and ran the CharacterPlayground scene and get a ton of console warnings about missing monobehaviors and scripts. That's not a good first impression. :confused:

    The warnings look similar to this:

    Code (plaintext):
    1. The referenced script (Unknown) on this Behaviour is missing!
    2. The referenced script on this Behaviour (Game Object 'Text') is missing!
    But the good news is that it seems these warnings don't affect the KCC itself and as far as I can tell, the KCC is working just fine in the playground scene. Time to dive into the documentation. :)
     
  17. AdamSingle

    AdamSingle

    Joined:
    Apr 18, 2013
    Posts:
    22
    I haven't had any issues. I just have a binding set up on WASD to provide a vector2 which I'm storing as my _moveAxis and setting it directly in the Inputs struct

    Code (CSharp):
    1.  
    2.     private void Awake()
    3.     {
    4.         _inputActions.Player.Move.performed += Move_performed;
    5.     }
    6.  
    7.     private void Move_performed(InputAction.CallbackContext obj)
    8.     {
    9.         _moveAxis = obj.ReadValue<Vector2>();
    10.     }
     
    transat likes this.
  18. nosty3

    nosty3

    Joined:
    Jan 23, 2015
    Posts:
    3
    Hi all,
    I'm really impressed by KCC, but I have one problem: MaxStableDistanceFromLedge = 0 seems to be working pretty good if the Character is on ledge and starts to slide.
    But it doesn't work at all if the Character jumps on ledge (see screenshot).
    Is any way to prevent situations like this? Thank you.

    ledge2.jpg
     
    vplampinen likes this.
  19. Zebbi

    Zebbi

    Joined:
    Jan 17, 2017
    Posts:
    521
    I doubt I'll get a reply, but is it possible to use Flowcanvas with KCC? I tried replicating the first steps in the guide and just get
    Code (CSharp):
    1. NullReferenceException: Object reference not set to an instance of an object
    2. KinematicCharacterController.KinematicCharacterMotor.UpdatePhase1 (System.Single deltaTime) (at Assets/KinematicCharacterController/Core/KinematicCharacterMotor.cs:757)
    3. KinematicCharacterController.KinematicCharacterSystem.Simulate (System.Single deltaTime, System.Collections.Generic.List`1[T] motors, System.Collections.Generic.List`1[T] movers) (at Assets/KinematicCharacterController/Core/KinematicCharacterSystem.cs:195)
    4. KinematicCharacterController.KinematicCharacterSystem.FixedUpdate () (at Assets/KinematicCharacterController/Core/KinematicCharacterSystem.cs:131)
    5.  
     
  20. transat

    transat

    Joined:
    May 5, 2018
    Posts:
    779
    @PhilSA... Questions for you:

    - what's the recommended way to pause KCC if I switch my character to Unity's third person controller before mounting a horse (using Horse Animset Pro)? For some reason my character switches to a T pose for a frame after they have finished mounting and I'm not sure what's causing this.

    - I'm setting up my root-motion driven KCC character to jump, does the code from the walkthrough #4 need to change substantially? I'm assuming some settings no longer apply? If so, which of the following can I ditch?

    Screen Shot 2020-05-14 at 5.01.03 pm.png
     
  21. jupando

    jupando

    Joined:
    Nov 17, 2014
    Posts:
    9
    @PhilSA
    Hi! I am using the asset NodeCanvas to design my character behaviors for a complex 3D action game. The example character controller included with KCC has all of the different behavior states built in to the single script, but this paradigm will not scale appropriately to the number of states my character will have.

    Until purchasing KCC, I had been using unity's character controller and then separating all of the specific behavior code for different states into their own scripts, called ActionTasks in NodeCanvas's system. I intend to continue using this pattern for my game but need to adapt KCC to this pattern.

    It seems like the most straightforward way to do this is to have each of my ActionTasks derive from ICharacterController and implement their desired behavior from there, and when the character changes states I would set the Kinematic Character Motor's controller to the current state's Action Task. Does this sound reasonable? If so, is there a particular way I should handle this? Maybe the proper way to do this would be to set the character's desired state in NodeCanvas, and then actually change the Motor's CharacterController in the current controller's AfterCharacterUpdate. Would that last step be necessary? Thanks much!
     
    FlavioIT and andreiagmu like this.
  22. transat

    transat

    Joined:
    May 5, 2018
    Posts:
    779
    I'm also interested in doing this so let me know how you go.
     
  23. Yggdrazyl

    Yggdrazyl

    Joined:
    Jul 12, 2017
    Posts:
    16
    In this case, how would you handle variable gravity ?
     
  24. my_little_kafka

    my_little_kafka

    Joined:
    Feb 6, 2014
    Posts:
    87
    Hello! Currently I'm in a bit of a pickle, I need a Character Controller for both Player Character and NPCs to do exactly the same:

    • The controllers never push each other
    • The NPCs use root motion to drive their movement, but even if there's an animation of an NPC lunging forward with a sword towards someone, this animation won't move that someone (be it PC or NPC), as in the first rule
    • The NPCs are confined on the NavMesh and can't leave it.
    What I'm doing now with the out of the box solutions in Unity is that I use NavMeshAgent to calculate the path and rotate the NPC towards the closest point while the root motion moves the NPC forward with CharacterController's Move(), I use the same method on PC and it provides me with the "no pushing" behaviour that I require.

    The problem is, if an NPC makes a certain move, like a dodge to the side, for example, the CC and NMA can get desynced - NMA is still on the navmesh, while CC is out of navmesh, because it dodged out of it.
    So I need to explicitly tell the CC to assume the NMA's position, even if I use NMA just to rotate the NPC towards the closest navigation point, I don't use it to move, because Unity's CharacterController is handling the movement.
    I had use some hacky solutions to achieve that, but, ultimately, I encountered a lot of problems with CC which I can't fix at all, mainly - if the NPCs CC radius is too high (and I need bigger CCs for giant enemies, for example), it will randomly fly up when colliding with other smaller CCs, including PC's CC, which is not very good for my game.

    The WebGL demo of this Character Controller is very impressive and it does so many things that would just break the standard Unity's Character Controller, but I would like to know - if it's possible to lock a Kinematic Character Controller driven NPC on a standard Unity's navmesh so it won't break the navigation, but also with the fact that the KCC is locked on navmesh won't break the physics of this Character Controller?
     
    Last edited: May 18, 2020
  25. keybol23

    keybol23

    Joined:
    Aug 13, 2013
    Posts:
    26
    I am really satisfied with this asset. Thank you very much for this. I have one question, how do I make a player not able to stand on another player. I still want a collider between players, but I just want to have another player slide off on top of each other instead of being able to stand on top.
     
  26. Vincent454

    Vincent454

    Joined:
    Oct 26, 2014
    Posts:
    167
    You can uncheck the player layer in the KinematicCharacterMotor in StableGroundLayers
     
    andreiagmu likes this.
  27. keybol23

    keybol23

    Joined:
    Aug 13, 2013
    Posts:
    26
    I see. Thanks a lot! I like that so much. I wish I can do that to my Barrels so they wont stuckpile up. Is there a way to put Kinematic Motor to objects to take advantage features like that?
     
  28. Vincent454

    Vincent454

    Joined:
    Oct 26, 2014
    Posts:
    167
    Since you can only use a capsule collider which cannot rotate this only works if your barrels dont rotate either xD
     
  29. sateyr

    sateyr

    Joined:
    Mar 6, 2013
    Posts:
    10
    Hi, i'm trying to implement a pull/pussh system to move any objets of the scene like the example in this game


    I have read some posts, but i'm not sure of what is the best way to do it using the kinematic character controller.

    Basic logic
    · Press a button and detect if the character have a draggable object in front
    · Change the state of the character and the dragable object to sync movement (Move the sane amount)
    · How to check the collisions of the draggable object and the character (corners, ledge..)?¿ If the object cant move, the character neither
    · Drop the draggable object if it falls (Gravity) OPTIONAL

    do i have to use a PhysicsMover in the draggable object?
     
    Last edited: May 28, 2020
  30. Berserker44

    Berserker44

    Joined:
    Sep 1, 2013
    Posts:
    29
    So I was able to implement a solid state based character system with KCC. The one issue I ran into recently is that each state I make relies on me setting the state to motor.CharacterController. This is fine, but I am in a situation where I need to run two states that use ICharacterController parallel to each other for a brief period. Unfortunately, the I can really only have one motor on the character, which means I can not the two states simultaneously. Is there anyway to run two ICharacterController simultaneously?
     
  31. sbsmith

    sbsmith

    Joined:
    Feb 7, 2013
    Posts:
    126
    Are there any global project settings that can affect the behaviour of KCC? I have an existing project with KCC imported and a new project. Same version of Unity (2018.4.14) and same version of KCC (3.2.1). In the existing project, the CharacterPlayground scene has the character immediately fall through the floor. Global physics settings for the two projects are identical except for the layers, but both allow Default to collide with Default. The existing project had an older version of KCC installed, but I deleted the folder entirely before importing the update.

    Update:
    I just realized what the problem was. When you open the CharacterPlayground scene, the ExampleCharacter does not have a layer set (The Layer dropdown just shows blank). In the new project that works but in the existing project, I needed to set the ExampleCharacter to be on Default before it could properly interact.
     
    Last edited: May 26, 2020
  32. keybol23

    keybol23

    Joined:
    Aug 13, 2013
    Posts:
    26
    Thanks.
    Another question. I have made the player's Max Stable Slope Angle to zero so it will never be able to stand or hover on an object. However, I still want the player to be able to walk on slopes like ramps and so on. How can I put different max stable slope angle working each for Stable Ground Layers and Unstable Ground Layers.
     
  33. Vincent454

    Vincent454

    Joined:
    Oct 26, 2014
    Posts:
    167
    I dont think you can do that, however I dont understand why you would set the max stable slope angle to 0 since I think you wont even be able to walk on slightly uneven terrain properly. If you just want to slide off of other players it will work regardless of your max stable slope angle since they use a capsule collider.
     
  34. sateyr

    sateyr

    Joined:
    Mar 6, 2013
    Posts:
    10
    And why don't you create another additional state, which is a mix of the other two?

    About create a solid state system. I have create one based in this system and it works nice with the KCC
     

    Attached Files:

    transat likes this.
  35. jupando

    jupando

    Joined:
    Nov 17, 2014
    Posts:
    9
    I have it working - I decided to go with a system where I switch out the velocity handling function when I enter new behavior states. I keep track of player input based velocity, and extra velocity(gravity, impact forces etc) separately so that I don't lose it between movement states.
    Code (CSharp):
    1. public void UpdateVelocity(ref Vector3 currentVelocity, float deltaTime)
    2.         {
    3.             if (CurrentVelocityHandler != null)
    4.             {
    5.                 TargetMovementVelocity = CurrentVelocityHandler(TargetMovementVelocity, deltaTime);
    6.             }
    7.             else
    8.             {
    9.                 if (Motor.GroundingStatus.IsStableOnGround)
    10.                 {
    11.                     TargetMovementVelocity = Vector3.Lerp(currentVelocity, Vector3.zero, 1f - Mathf.Exp(-StableMovementSharpness * deltaTime));
    12.                 }
    13.             }
    14.  
    15.             // Gravity
    16.             if (ApplyGravity && !Motor.GroundingStatus.IsStableOnGround)
    17.             {
    18.                 ExtraVelocity += Gravity * deltaTime;
    19.             }
    20.             else
    21.             {
    22.                 ExtraVelocity = Vector3.zero;
    23.             }
    24.  
    25.             // Handle jumping
    26.             _jumpedThisFrame = false;
    27.             _timeSinceJumpRequested += deltaTime;
    28.             if (_jumpRequested)
    29.             {
    30.                 MayJump = !_jumpConsumed && ((AllowJumpingWhenSliding ? Motor.GroundingStatus.FoundAnyGround : Motor.GroundingStatus.IsStableOnGround) || _timeSinceLastAbleToJump <= JumpPostGroundingGraceTime);
    31.                 // See if we actually are allowed to jump
    32.                 if (MayJump)
    33.                 {
    34.                     // Calculate jump direction before ungrounding
    35.                     Vector3 jumpDirection = Motor.CharacterUp;
    36.                     if (Motor.GroundingStatus.FoundAnyGround && !Motor.GroundingStatus.IsStableOnGround)
    37.                     {
    38.                         jumpDirection = Motor.GroundingStatus.GroundNormal;
    39.                     }
    40.  
    41.                     //Jump direction is halfway between normal direction and gravity
    42.                     jumpDirection = (jumpDirection + -Gravity.normalized).normalized;
    43.  
    44.                     // Makes the character skip ground probing/snapping on its next update.
    45.                     Motor.ForceUnground();
    46.  
    47.  
    48.                     //Add the jump velocity to the gravity vector
    49.                     ExtraVelocity += (jumpDirection * agent.stats.baseJumpVelocity) - Vector3.Project(currentVelocity, Motor.CharacterUp);
    50.                     ExtraVelocity += (MoveInputVector * JumpScalableForwardSpeed);
    51.  
    52.                     float newVerticalVelocity = Vector3.Project(TargetMovementVelocity + ExtraVelocity, Motor.CharacterUp).y;
    53.  
    54.                     _jumpRequested = false;
    55.                     _jumpConsumed = true;
    56.                     _jumpedThisFrame = true;
    57.                 }
    58.             }
    59.  
    60.  
    61.             // Take into account additive velocity
    62.             if (_internalVelocityAdd.sqrMagnitude > 0f)
    63.             {
    64.                 //currentVelocity += _internalVelocityAdd;
    65.                 TargetMovementVelocity += _internalVelocityAdd;
    66.                 _internalVelocityAdd = Vector3.zero;
    67.             }
    68.  
    69.             currentVelocity = TargetMovementVelocity + ExtraVelocity;
    70.  
    71.         }
    Here is an example of a movement behavior state and assigning a new velocity handler function:

    Code (CSharp):
    1. using NodeCanvas.Framework;
    2. using ParadoxNotion.Design;
    3. using UnityEngine;
    4. using KinematicCharacterController;
    5.  
    6. namespace Stellar
    7. {
    8.  
    9.     [Category("Movement")]
    10.     [Description("Basic movement")]
    11.     public class GroundedMovement : ActionTask<Agent>
    12.     {
    13.         public BBParameter<float> speedScalar;
    14.         public BBParameter<float> rotScalar;
    15.  
    16.         //Use for initialization. This is called only once in the lifetime of the task.
    17.         //Return null if init was successfull. Return an error string otherwise
    18.         protected override string OnInit()
    19.         {
    20.             return null;
    21.         }
    22.  
    23.         //This is called once each time the task is enabled.
    24.         //Call EndAction() to mark the action as finished, either in success or failure.
    25.         //EndAction can be called from anywhere.
    26.         protected override void OnExecute()
    27.         {
    28.             agent.speedScalar = speedScalar.value;
    29.             agent.rotationScalar = rotScalar.value;
    30.  
    31.             agent.controller.CurrentVelocityHandler = Move;
    32.         }
    33.  
    34.         //Called once per frame while the action is active.
    35.         protected override void OnUpdate()
    36.         {
    37.          
    38.         }
    39.  
    40.         //Called when the task is disabled.
    41.         protected override void OnStop()
    42.         {
    43.             agent.controller.CurrentVelocityHandler = null;
    44.         }
    45.  
    46.         //Called when the task is paused.
    47.         protected override void OnPause()
    48.         {
    49.  
    50.         }
    51.  
    52.         Vector3 Move(Vector3 currentVelocity, float deltaTime)
    53.         {
    54.             KinematicCharacterMotor Motor = agent.controller.Motor;
    55.             float currentVelocityMagnitude = currentVelocity.magnitude;
    56.  
    57.             Vector3 effectiveGroundNormal = Motor.GroundingStatus.GroundNormal;
    58.             if (currentVelocityMagnitude > 0f && Motor.GroundingStatus.SnappingPrevented)
    59.             {
    60.                 // Take the normal from where we're coming from
    61.                 Vector3 groundPointToCharacter = Motor.TransientPosition - Motor.GroundingStatus.GroundPoint;
    62.                 if (Vector3.Dot(currentVelocity, groundPointToCharacter) >= 0f)
    63.                 {
    64.                     effectiveGroundNormal = Motor.GroundingStatus.OuterGroundNormal;
    65.                 }
    66.                 else
    67.                 {
    68.                     effectiveGroundNormal = Motor.GroundingStatus.InnerGroundNormal;
    69.                 }
    70.             }
    71.  
    72.             // Reorient velocity on slope
    73.             currentVelocity = Motor.GetDirectionTangentToSurface(currentVelocity, effectiveGroundNormal) * currentVelocityMagnitude;
    74.  
    75.             // Calculate target velocity
    76.             Vector3 inputRight = Vector3.Cross(agent.controller.MoveInputVector, Motor.CharacterUp);
    77.             Vector3 reorientedInput = Vector3.Cross(effectiveGroundNormal, inputRight).normalized * agent.controller.MoveInputVector.magnitude;
    78.             Vector3 targetMovementVelocity = reorientedInput * agent.stats.baseMoveSpeed * speedScalar.value;
    79.  
    80.             // Smooth movement Velocity
    81.             Vector3 TargetVelocity = Vector3.Lerp(currentVelocity, targetMovementVelocity, 1f - Mathf.Exp(-agent.controller.StableMovementSharpness * deltaTime));
    82.  
    83.             agent.controller.SetTargetVelocity(TargetVelocity);
    84.             return TargetVelocity;
    85.         }
    86.     }
    87. }
     
    Last edited: Jun 4, 2020
    transat likes this.
  36. transat

    transat

    Joined:
    May 5, 2018
    Posts:
    779
    Cool @justinpando I'll have a look. I haven't attempted my NodeCanvas version yet but have a decent FSM happening with each state inheriting from a default state that keeps track of stuff that needs to persist across states. The states can be drag and dropped in the inspector. Here it is with a couple of the states opened up...

    Screen Shot 2020-06-04 at 11.34.18 am.png

    Individual states can inherit as much or as little as they need. Often it's just UpdateVelocity().
    I'm using MxM Motion matching to drive the root motion anims.
     
    Last edited: Jun 4, 2020
  37. DukeRoderick

    DukeRoderick

    Joined:
    Dec 25, 2015
    Posts:
    15
    Hello, has anyone had luck making it so that the capsule collider can have it's orientation changed? I'm working on a game where the player is controlling an animal, and would like the capsule to be horizontal rather than vertical. A lot of the Kinematic Character Motor logic is set up though with the expectation of the capsule being exclusively vertical. I wanted to see if anyone using this asset has had luck with changing or making it work with different shaped characters before I started mucking about in the code trying to get it to work myself.

    Thanks!
     
  38. keybol23

    keybol23

    Joined:
    Aug 13, 2013
    Posts:
    26
    It's because I don't want players to be standing or hovering on top of other objects. I want them to slide down quickly. If I set the slope to higher than zero they hover on top of these objects instead of quickly snapping/sliding to the ground which zero slope does.
     
  39. DragonSix

    DragonSix

    Joined:
    Jul 2, 2013
    Posts:
    37
    When I have a group of characters colliding with one-another it seems the Kinematic controller is generating a MASSIVE amount of garbage.

    Capture2.JPG
    Those huge garbage mountains in the graph are only from the Kinematic thing here, otherwise the code is at 0B.

    My controller code is basically the same as the sample one. I'm not executing any custom code on inter-character collision.
    What happens is just a bunch of characters walking in close contact to each other while they all try to reach a common destination.

    What is happening? Why is it leaking like that and what can I do to avoid it?

    EDIT: So... of course... I can see this is linked to the fact that I've given rigidbodies to those characters, I do it because I need these to be detected by triggers. As soon as I remove the rigidbody, the garbage disappears. Eh... I would've preferred if this caused no issues.
     
    Last edited: Jun 17, 2020
  40. CodeBison

    CodeBison

    Joined:
    Feb 1, 2014
    Posts:
    289
    Have you tried profiling a build? It looks like what might be happening there is a bunch of editor-only allocations that are intended to give more debug info in the case a GetComponent call results in a null result. You'll likely find that a build doesn't allocate memory for those sections. You'll see them talking about it here (search the page for "when you call GetComponent").
     
    DragonSix likes this.
  41. DragonSix

    DragonSix

    Joined:
    Jul 2, 2013
    Posts:
    37
    Oh, yes indeed! It doesn't happen outside of the editor.
    I never came across that particular behavior before and I just assumed it would affect the build. But as you said, build profile is clean and free of garbage.

    So there was no issue. Thanks!
     
    CodeBison likes this.
  42. jupando

    jupando

    Joined:
    Nov 17, 2014
    Posts:
    9
    After reading through the documentation it looks like it's just not supported. Is there some reason you absolutely have to use a horizontally oriented collider versus an approximate vertical one? The only other suggestion I might have is to tether another collider to your main motor object.
     
  43. SGiygas

    SGiygas

    Joined:
    Jan 18, 2017
    Posts:
    6
    I've been experimenting with the KCC for a while now and I've found a peculiar "error" (if you can call it that). It seems that when step offsetting is in effect, the ground normal seems to change drastically (For example I made a staircase at 45° and the normal returned angles between 25° and 65°). This makes it rather bothersome to use step offsetting for a motor that has a max stable ground angle below that range. Is there any way to work around this or "fix" it?

    Edit: By fixing I mean have the normal at an angle of approximately 45°. I am aware that I could just use a flat surface collision mesh instead
     
  44. GAMER_HUA

    GAMER_HUA

    Joined:
    May 30, 2018
    Posts:
    1
    I would like to achieve such a thing that a heavy body can push light, by using interactive rigidbody handling and rigidbody interaction type ,it seems works, but I'm not sure it is the correct way. And it brings new problems, when I use constraints settings that I can only move in the XY plane one will push the other out of the wall, Is there any way to solve it?
     
  45. Ruchir

    Ruchir

    Joined:
    May 26, 2015
    Posts:
    934
  46. vincewins

    vincewins

    Joined:
    Dec 19, 2016
    Posts:
    21
    I want to build a cylinder platform that raises height when the player (KCC) steps upon it.
    I thought this is gonna be easy, but now I am struggling with how to setup the platforms rigidbody, collider and trigger. Especially since KCC does not use rigidbody itself.

    My GameObjects structure is like this now:
    root (with rigidbody and script that detects onTriggerEnter and onCollisionEnter)
    -- childA (with collider for collision with KCC, handling walking on it, etc.)
    -- childB (with triggerCollider for detecting if a certain area is overlapped)

    What I tried:
    Either I use "IsKinematic: true" on the other gameObjects root rigidbody > but then the Trigger is not fired,
    or I use "IsKinematic: false" on the root rigidbody > then the trigger is fired, but I have no collision and the players clips through the object

    Do I need multiple root-level rigidbodies and respective children to achieve this or is there an easier / more maintainable solution?
     
    Last edited: Jun 23, 2020
    andreiagmu likes this.
  47. Zebbi

    Zebbi

    Joined:
    Jan 17, 2017
    Posts:
    521
    @PhilSA not sure if you're around anymore, but is it possible to use KCC with Flowcanvas or Bolt? Getting either tool to figure out what KCC seems to be a bit difficult with types and such, is there a specific method to get it working?
     
  48. MaPiDev

    MaPiDev

    Joined:
    Aug 29, 2018
    Posts:
    21
    @PhilSA I am trying to use KCC in combination with Cinemachine. More specifically, I am working on a third-person controller. For this, I am using the "3rdPersonWithAimMode" example Cinemachine setup that is provided by Cinemachine. I set up my character the same way you do in your examples. Separated in Player and Character objects. I am also using the "Frame Perfect Rotation" settings that you provide as an example. However, while moving around the character is smooth, rotating the character results in jitter. This is especially noticeable while using the "Aim Camera". The character is not lagging behind like without the "Frame Perfect Rotation" but the rotation is just not smooth.
     
    vincewins likes this.
  49. Streamfall

    Streamfall

    Joined:
    Aug 8, 2011
    Posts:
    43

    Hi @Zebbi, I am curious about how you handled edges.
    In my case, I was hoping to do a similar thing (sort of the same as how collisions work, but with edge detection) and I ended up adding an invisible collider with my level geometry. This collider is tagged so I know what I'm running into. For animations sake / slowing down ahead of time, etc - a raycast sweep forward from the gameobject with character model on it would be a good start to detecting them ahead of time. I haven't tried this yet, if you've found a solution let's compare notes?
     
  50. sateyr

    sateyr

    Joined:
    Mar 6, 2013
    Posts:
    10
    I share the solution I have received, for anyone who needs it in the future ^^

    "
    • The block is a simple kinematic rigidbody
    • When the character starts grabbing a block, disable the character controller as a whole
    • Replace it with a "BlockController" which is a script that moves the block within the constrained block movement area (the indented area in the ground) based on inputs. This is the part you'll need to solve by yourself
    • At every frame when the block is being grabbed, place your character at an offset from the block's current position
    • if the block would fall, un-grab the block, reactivate your character controller, and make the block rigidbody non-kinematic to make it fall
    " (PhilSA)

    I love the robust that is this asset
    https://twitter.com/sateyr/status/1271751689490620416 (Work in progress)
     
    TomatoLamp likes this.