#Kinematic Character Controller Woes.

1 messages · Page 1 of 1 (latest)

latent jetty
#

My bro and I are having a serious problem with this Unity asset.
https://assetstore.unity.com/packages/tools/physics/kinematic-character-controller-99131?srsltid=AfmBOor2eLxcafBRs5kLH27sFyOMo7TgzlfmYddqkrnpMelUAgcgu87F
Despite our efforts, we can't seem to make an animated character work with it.

Get the Kinematic Character Controller package from Philippe St-Amand and speed up your game development process. Find this & other Physics options on the Unity Asset Store.

#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using KinematicCharacterController;
using KinematicCharacterController.Examples;

public class ExampleCharacterAnimator : MonoBehaviour
{
    public ExampleCharacterController chara;
   public Animator anim;
   public Vector3 posDiff;

    // Update is called once per frame
    void Update()
    {
        anim.SetFloat("Speed", (transform.position-posDiff).magnitude*Time.deltaTime*60*60);
        anim.SetBool("Grounded", chara.Motor.GroundingStatus.IsStableOnGround);

        posDiff = transform.position;
    }
}

This is the code my bro made to try to handle the animation.

lusty geyser
#

Can you do what you've been suggested to do?

latent jetty
#
Checked what’s going on in animator at runtime.

Showed animator screenshot.

Checked if animation was set to looping. It is.```
These are the suggestions I have received.
#

"Speed Numbers are fluctuating wildly between a small amount and double digit values"
-Chirz

#

Did I miss any suggestions?

lusty geyser
#

Even this screenshot cuts half of the animator out.

split raft
lusty geyser
#

I don't see shit in that screenshot. The states names are too blurry.

#

Does it stay in that first state? Does it seem to loop it? Or is it's progress stuck at the start of the state?

latent jetty
#

In runtime, the bar in the first state highlighted in orange (which is labelled "Idle Walk Run Blend") doesn't seem to fill at all.

split raft
#

There's a blend tree, but the Speed value is going ALL over the place

fresh hornet
#

There's a blend tree, but the Speed value is going ALL over the place
I'd maybe put a breakpoint in the code to see what your speed calculation evaluates to and why.
The kinematic character controller is likely moving your transform out of sync. It could be that you need to do your speed calculation in FixedUpdate, or set the posDiff in LateUpdate after the character controller has finished updating the transform.

#

The latter would be the first thing I'd try before digging into the character controller code.

latent jetty
#

Okay, changing Update to LateUpdate seems to have stabilized the speed value, but it's stuck at the first frame of the run animation.

Chirz is investigating further.

split raft
#

So we've resolved that mystery. But the animator was designed for a different script, and without the values we need exposed, I can't figure out how to make the animator work right

fresh hornet
#

Someone will inevitably tell you to post in #🏃┃animation so I might as well be the one 😅 You've also got a lot more animator experts lurking over there

steel iron
latent jetty
#

(And there were some other things my bro did to the code.)

#

This is the script that my bro wrote to handle animations.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using KinematicCharacterController;
using KinematicCharacterController.Examples;

public class ExampleCharacterAnimator : MonoBehaviour
{
    public ExampleCharacterController chara;
   public Animator anim;
   public Vector3 posDiff;

    // Update is called once per frame
    void LateUpdate()
    {
        anim.SetFloat("Speed", ((transform.position-posDiff).magnitude/Time.deltaTime)/4);
         anim.SetFloat("MotionSpeed", ((transform.position-posDiff).magnitude/Time.deltaTime)/10);
        anim.SetBool("Grounded", chara.Motor.GroundingStatus.IsStableOnGround);

        posDiff = transform.position;
    }
}

Here's what it looks like now.

latent jetty
steel iron
#

In the SetFloat function, why are you guys dividing the position delta by Time.deltaTime and then dividing again?

latent jetty
split raft
steel iron
#

So you can just set this code to

anim.SetFloat("Speed", Motor.BaseVelocity.magnitude);

And then in your Blend Tree, set whatever the max speed is to be the upper limit of the blend.