I’m trying to subclass AIpath to use with Kinemetic Character Controller. First, I had to virtual both FinalizeRotation and FinalizePosition:
void FinalizeRotation (Quaternion nextRotation) {
void FinalizePosition (Vector3 nextPosition) {`
Then I tried a simple script that passed the vector into KCC:
public class AIBridge : AIPath
{
ForkedExampleCharacterController KCC;
// Start is called before the first frame update
void Start()
{
KCC = GetComponent<ForkedExampleCharacterController>();
}
public override void FinalizePosition (Vector3 nextPosition) {
Debug.Log("test");
AICharacterInputs inputs = new AICharacterInputs();
Vector3 currentPosition = simulatedPosition;
inputs.MoveVector = currentPosition;
KCC.SetInputs(ref inputs);
}
}
I also noticed accumulatedMovementDelta wasn’t available in the subclass so I protected it:
protected Vector3 accumulatedMovementDelta = Vector3.zero;
I tried another method:
protected override void FixedUpdate () {
if (canMove) {
Vector3 nextPosition;
Quaternion nextRotation;
MovementUpdate(Time.fixedDeltaTime, out nextPosition, out nextRotation);
FinalizeMovement(nextPosition, nextRotation);
}
}
public override void FinalizePosition (Vector3 nextPosition) {
if (updatePosition) {
AICharacterInputs inputs = new AICharacterInputs();
inputs.MoveVector = nextPosition * Time.deltaTime;
Debug.Log(inputs.MoveVector);
KCC.SetInputs(ref inputs);
}
else{
AICharacterInputs inputs = new AICharacterInputs();
inputs.MoveVector = Vector3.zero;
}
}
I’ve tried overriding the entire function but it just moves my AI forward endlessly:
public override void FinalizePosition (Vector3 nextPosition) {
// Use a local variable, it is significantly faster
Vector3 currentPosition = simulatedPosition;
bool positionDirty1 = false;
if (updatePosition) {
tr.position = currentPosition;
AICharacterInputs inputs = new AICharacterInputs();
inputs.MoveVector = (nextPosition - currentPosition) + accumulatedMovementDelta;
Debug.Log(inputs.MoveVector);
KCC.SetInputs(ref inputs);
currentPosition = tr.position;
//if (Motor.GroundingStatus.IsStableOnGround) verticalVelocity = 0;
}
// Clamp the position to the navmesh after movement is done
bool positionDirty2 = false;
currentPosition = ClampToNavmesh(currentPosition, out positionDirty2);
// Assign the final position to the character if we haven't already set it (mostly for performance, setting the position can be slow)
if ((positionDirty1 || positionDirty2) && updatePosition) {
// Note that rigid.MovePosition may or may not move the character immediately.
// Check the Unity documentation for the special cases.
if (rigid != null) rigid.MovePosition(currentPosition);
else if (rigid2D != null) rigid2D.MovePosition(currentPosition);
else tr.position = currentPosition;
}
accumulatedMovementDelta = Vector3.zero;
simulatedPosition = currentPosition;
UpdateVelocity();
}
Ultimate it just sends the KCC controller walking forwards endlessly, not pathing at all to any point. @aron_granberg can you suggest a better way of integrating A*PP with other character controller assets, maybe some sort of hook would be useful, so if a controller override script is added to the object, we can just hook into the part of FinalizePosition that sets the movement for our own custom controller?