nicholas-maltbie / openkcc Goto Github PK
View Code? Open in Web Editor NEWOpen Source Kinematic Character Controller for Unity
Home Page: http://nickmaltbie.com/OpenKCC/
License: MIT License
Open Source Kinematic Character Controller for Unity
Home Page: http://nickmaltbie.com/OpenKCC/
License: MIT License
It seems like if you try to walk into corner that is is wider than 90 degrees character starts to jitter a lot in place.
To solve it I checked source code for PhysX character controller and here is something I found:
// https://github.com/NVIDIAGameWorks/PhysX-3.4/blob/master/PhysX_3.4/Source/PhysXCharacterKinematic/src/CctCharacterController.cpp
// From Quake2: "if velocity is against the original velocity, stop dead to avoid tiny occilations in sloping corners"
if((currentDirection.dot(direction)) <= 0.0f)
break;
Surprisingy enough, adding this to sweep test loop indeed solved the problem.
direction
represents initial direction of the sweep and currentDirection
is projected since last hit
Right now the network relative parent synchronizes state via a NetworkVariable
but it would be much better to update this to a direct buffer similar to netcode's NetworkTransform.
Basically need to do the same thing as the existing network transform but instead of synchronization in local space relative to parent, synchronize in relative parent space according to the current KCC movement model. Also, don't worry about synchronization of scale for now as that is a bit beyond the current scope.
And also, this synchronization should be controlled by a RelativeParent struct (should refactor that code in the KCCMovementEngine as well... at least let the end user disable it if they don't want to use it).
Add some features to mole movement
Switch character controls to be managed using a Finite State Machine (FSM) based model. Integrate the Coyote state machine framework into the project for managing the state transitions and actions.
In addition, switch sample character controller to now work based off of FSM model along with any other example character controllers in the future.
Add some documentation in the contributing section about how to configure a UNITY_LICENSE
secret in forked repos so they can run the pull request validation workflows as well.
Additionally, if no code changes are made (in Assets/Packages folder), then it's probably ok to skip code, test, and build validation if only changes are made to docs/.md
files.
Two things for this issue
UNITY_LICENSE
secret for forked reposAdd support for an on screen joystick (two of them) for mobile controls on a phone so the player can be moved easily.
Unity WebGL builds no longer fail for mobile devices so it would be nice to support them.
From YT comment suggestion by Rob Gustafson.
Describe the bug
When importing the project in a fresh unity install, unable to import the state machine unity package as part of the build dependencies.
To Reproduce
Import the project via git and unable to resolve the dependency.
Expected behavior
Expected to import dependent projects automatically
Screenshots
TBD
Additional context
REAVER
couldnt import the project, ffs this package manager shenanigans
Nick Maltbie
What’s the error you’re running into? Someone helped me debug some import errors on GitHub to patch for version 1.0.1 :)
I should update the readme to reference that version instead of 1.0.0
REAVER
@nicholas-maltbie for example unity cant get your StateMachineUnity package(i fed git url to package manager)
(other packages of yours are downloaded correctly)
Nick Maltbie
Oh, that makes sense. You should be able to download it via git manually with a path like this - https://github.com/nicholas-maltbie/StateMachineUnity.git#release/v1.1.0
There is also an archive of the package on npmjs if you want to just download and import manually if the auto import isn't working! https://www.npmjs.com/package/com.nickmaltbie.statemachineunity
Let me know if you need any help with it.
REAVER
@nicholas-maltbie trying it again rn, im going to make empty project, install all prerequisite packages then download manually your project, then drop the assets folder to my fresh project. Sounds robust to me
REAVER
@nicholas-maltbie nope, still no succes. Unity cant fetch the StateMachineUnity, im feeding unity your given link
Improve the KCCStateMachine to account for other kinds of moving ground that aren't attached via parent object (such as rigidbody) and ensure that they can work as expected for the player.
Add some sort of automated integration tests as well in Playmode to verify this behaviour.
Add example to project to keep humanoid character feet grounded and locked in place when moving to have animations line up with player movement.
Adding basic foot IK as part of PR #197
Future features left to add:
With the latest version of this package as of this writing (1.0.0), i get errors of dependencies that aren't present in the project:
With older versions (0.1.2), this didn't happened. The package worked as expected.
For context, these are the details of the project:
Add animation documentation for where animations are referenced from and how to modify/configure/add animations via Mixamo for existing or different models.
Describe the bug
Currently a bug with the KCC animation where the player will start their falling animation while they are still standing on the ground.
This is caused because the falling animation will play whenever the player is standing on a steeply sloped surface or whenever they are off the ground. These two states should have different animations. Also, when sliding, the player should have some maximum bounded velocity so they cannot build up infinite velocity.
To Reproduce
Steps to reproduce the behavior:
I will upload a gif of this situation from a rest branch soon.
Expected behavior
They player should instead show a sliding animation and not be able to jump anymore instead of going straight to the falling animation.
Additional context
This also should be fixed as a "sliding" state when the player transitions to a FSM based model.
Is your feature request related to a problem? Please describe.
Feature request for the project: an example third person character controller with camera looking top down with movement controlled via mouse or arrow keys. Have player mode rotate based on movement.
Include integration with nav-mesh/collision so player or NPC could move through 3D space and not clip through or into obstacles.
Describe alternatives you've considered
Could be achieved by using a new camera controller instead of the current first/third hybrid person camera controller.
Additional context
support camera & movement for a RPG similar to Baldur’s gate, wasteland, divinity original sin, pathfinder, Solista, etc...
Describe the bug
When standing on a moving platform that changes direction quickly, the character will snap forward or backward quickly.
To Reproduce
Steps to reproduce the behavior:
Go to any moving platform and stand on them to observe the broken player movement.
Additionally, when on a fast-moving vertical platform, the player's feet will sometimes get stuck in the floor. This may have to do with the player's position being delayed a frame from where they actually should be.
Expected behavior
Player should move smoothly with the object instead of this jittery movement.
Screenshots
N/A (low frame rate of a gif would make this behavior difficult to view)
Additional context
This is a well investigated issue and will most likely involve something related to late update or parenting the player object's transform. It seems to be just a visual bug for vertical platform movement but should be patched none the less.
Currently the demo scenes for the project are each hosted in their own build, this makes an excessively large build and uses a lot of resources. They should be joined into a single build with a menu to select between which scene the player wants to run.
Add a new parameter to the KCCMovementEngine similar to the existing ColliderCast.skinwidth from the built in character controller.
Since this is a big feature, I don't think I will try to add it as part of release 1.4.0, and will instead target adding this as part of 1.5.0. Some of the bug fixes discussed in issue #194 and issue #193 may be included in a later patch of 1.4.0, but the skin width features will not be included.
Goal of skin width:
All this code will also require testing, documentation, and various other additions to the project.
Features to add as part of SkinWidth:
Action Items from Issue #194
Action Items from Issue #195
KCCUtils.Epslion
being the default value.Extra Action Items
Switch integration tests to cover all scenarios and permutations of player movement.
This should include
Goal: Simplify the direct use of KCCMovementEngine
Use Case: I created a test scene and Unity Package that has a simple character that simply attempts to move in a direction on the XZ axis
As as starting point, I'd like to be able to use the KCCMovementEngine API alongside a simple KCCConfig to make it so the AI agent moves in each of the cardinal directions while making use of OpenKCC under the hood
See the picture below for the "Intended Behaviour"
It would be interesting if I could then swap the KCCMovementEngine for a KCCMoleEngine, enabling the character to run Up the walls like the mole would be able to, without changing any code, but I understand if this would also require a swap in KCCConfig as well
Below shows my current test case, where the AI Agent is instructed to desire a velocity of 1 along the X axis, and my non KCC solution simply moves the transform to the calculated position each frame.
The sample package that I will provide to you demonstrates how I created this script and includes commented sections that demonstrate how I would like to replace my naïve implementation with OpenKCC's Collision Solving.
Here is a snippet of how the code currently works and it includes an example of how I'd like to replace my naïve implementation with an OpenKCC API Call
void FixedUpdate()
{
// 1. Get Desired Velocity from Input Source
Vector3 newVelocity = testInputDirection * testSpeed;
// 2. Make Arbitrary Modifications to Velociyt Based on Character State
// newVelocity = speedBoost ? newVelocity * 2 : newVelocity;
// 3. Apply Movement to Character based on Calculated Velocity
ApplyMovement(newVelocity, Time.fixedDeltaTime);
}
void ApplyMovement(Vector3 velocity, float deltaTime)
{
// 1. Temporary, Non Collision Based Solution
transform.position += velocity * deltaTime;
// 2. Ideal Solution Using OpenKCC, Benefitting from Collision and
// Gravity Settings of the KCCMovementEngine and its IKCCConfig
/*
// _movementEngine.ApplyMovement(deltaTime, transform.position + velocity, true);
*/
}
Overall I want to greatly expand on this manual usage of the "mid-level" abstractions of OpenKCC, and I hope that this could be a decent starting point.
@tufanaydin6340
Hey question, i can't change "MinVerticalAngle" and "MaxVerticalAngle" when scene runs it turns default "-90 & +90" how can we change? i can't change.
I wasn't able to repro this bug but logging it for note. I was using the nickmaltbie.OpenKCC.CameraControls.CameraController class
Add support for CinemaMachine unity as an external package to support more types of camera control and camera modes. Add as a separate package so it's not required dependency and can be installed if required for another project. Should be version controlled with the rest of the package and all updated as a group.
Test out some additional features from cinema machine and ensure that they work correctly with the KCC state machine. Test some features including:
Make some samples for different player controller setups including:
Support movement and character rotation that doesn't have to follow camera. For ICameraController separate the camera heading and player heading so player doesn't always have to face the direction the camera is facing.
Add a KCC Movement Engine that supports movement via a floating capsule.
Have the capsule float a specific distance off the ground and it should create a capsule collider for this operation.
Given this expected distance to float off the ground, do a sphere cast downwards from the player location and lerp the position up/down as needed to move the player up or down as long as they are grounded.
This should handle stairs much more smoothly.
Error scenario where when a player is jumping up stairs a snap up event can interrupt their movement. This would be best resolved by preventing snapping up while the player is moving up or down.
Swapping version with a chapter selected doesn't load the new URL page properly.
Need to patch this behaviour in the main.js script.
Changing version on a page with a chapter selected should result like this:
https://nickmaltbie.com/OpenKCC/docs/manual/introduction.html#why-kinematic
to
https://nickmaltbie.com/OpenKCC/docs/v1.3.0/manual/introduction.html#why-kinematic
but instead results like this
https://nickmaltbie.com/OpenKCC/docs/manual/introduction.html#why-kinematic/../../v1.2.3/
Need to fix it to ignore the chapter tag when computing the new web link in the selectVersion
function.
OpenKCC/Documentation/templates/custom/styles/main.js
Lines 12 to 22 in 633a60a
Is your feature request related to a problem? Please describe.
I think a bit of documentation or any way to add features like climbing etc could be fine
Describe the solution you'd like
Im trying using third person controller to do a raycast and climb using animation and interpolation of pos but looks so ugly.
Describe alternatives you've considered
disable kcc while doing the animation
Additional context
Im ttesting using kcc + fusion to get something funny, but when i code my third person controller i cannot get kcc working like i want,
Document the bouncing and sliding behavior of the KCC with diagrams, explanations, and link to the existing YouTube video Moving Characters in Games.
Make sure to include a detailed description about how the bounces operation are computed as requested by BlinkAChu in the video comment.
Describe the bug:
When utilizing the newly updated KCC Movement Engine with a barebones client script, I got the unexpected behavior demonstrated in the following gif where the velocity when falling off an object starts strong and then resets to what I believe is my client side velocity
To Reproduce:
Steps to reproduce the behavior:
Expected behavior:
The expected behaviour is perhaps subjective, but there seems to be a disconnect between my intention on the client side (Visible in the fixed update method of SimpleMoveKCC) and the resulting output behaviour of the KCCMovementEngine.
Something that makes it harder for me to debug this on the client side is that there isn't an easy way in the inspector to look at the state of the KCCGroundedState that I'm passing into the KCCMovementEngine
I think that perhaps what I was expecting was a smooth fall off of the object when leaving the ground, but perhaps it could be expected for me on the client side to implement a sort of "Grace Period" for negative velocity when leaving a surface
My next move would likely be to make the grounded state variables visible in the inspector that way I can test my client code against a clearer picture of the state of the KCCMovementEngine
Side Note
As a Side Note, I also wanted to mention this separate issue where my client side code results in the following Behavior where the object overlaps with the ground for a frame before snapping back up
Optimize the Capsule Collider Cast Hit class to no longer allocate new memory after initialization.
Remove any instances of the word new
and change any phsyics operations to use a constant array to calculate the physics raycast, capsule cast, and capsule overlap operations.
I want to use OpenKCC for Navmesh/AI. At the same time OpenKCC want to be driven by player as well
I saw several samples just looking around but not sure what exactly to pick up and call it a day. Saw camera getting involved too which is only used by player but not AI. Would be nice if we get a sample keeping both in mind?
Describe the bug
In WebGL builds, a clickable Fullscreen button is generated so that users can play the game in fullscreen, which works as intended. However, when pressing Escape to edit game settings, Fullscreen is also exited similarly to the behavior when watching Youtube videos in fullscreen.
To resolve this, the pause/settings button should be rebound in WebGL builds to avoid this double binding, and this new binding should be displayed on screen for the demo.
To Reproduce
Steps to reproduce the behavior:
At this point, the game exits fullscreen. Pressing escape a second time allows the user to view the 'Settings' button.
Expected behavior
User presses the bound pause/settings button, and the settings menu becomes available. Pressing escape only exits fullscreen.
Describe the bug
OpenKCC works perfectly with a capsule collider cast, but there is also an alternative box collider cast. While this mostly works, the movement engine will occasionally slowly slide in a random direction on the floor (even with no input). I've observed some other unusual behaviours (like getting "caught" on flat ground) with box collider cast that do not occur with an equivalent capsule collider cast, though these may be down to implementation in my own project. The sliding issue, however, can be reproduced in the sample scene.
To Reproduce
In the sample scene for OpenKCC, unpack the character prefab and swap out the capsule collider and CapsuleColliderCast component for their respective box equivalents. Jump around a little bit on flat ground until the issue is observed.
I am trying to using openkcc for indie development.
when I try to move character to push these pushable box and ball ,it did not work well,just block my character's movemnt, is this a bug or there are some setting I need to open?
My unity version: 2022.2.15f1
Describe the bug
When a player stands on a slanted floor that is rotating, the player model will slowly drift towards the edge. This also only happens when the direction of the slant is not tangent to the axis of rotation.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
The player's position relative to the axis of rotation for the parent object should not change significantly.
Screenshots
N/A
Additional context
This may be difficult to fix and related to other issue #19
I observed this in the browser demo.
Describe the bug
Walking onto the stairs from the side may cause inappropriate "dropping" animation; it may transition into "falling" animation with character getting stuck.
To Reproduce
Walk into the stairs from the side. These stairs in the first screenshot at this angle seem reliable at reproducing at least the "dropping" phase.
Expected behavior
Clearly, walking up the stairs from any direction should not trigger "dropping" animation. Something's off at that point already.
Additional context
I was playtesting the demo and noticed irregularities in interactions with "knee-high" stair steps (e.g. leftmost big-step straight stairs, 3rd step of the spiral stairs). Normally they are too high but sometimes the character will just step up anyway like this:
And when I was trying out different angles/keys the 'real bug' happened (character is stuck):
Is your feature request related to a problem? Please describe.
I have gone through most of the documentation and most of you great videos on YouTube, but I am a beginner and haven't found a clear description of how to get started with OpenKCC. It is probably my noobness, but is there a simple tutorial which starts from scratch, adds the packages, gets a model in the scene and steps through the actions one needs to take to get OpenKCC to work in a Unity project?
Describe the solution you'd like
Either a document or YouTube video going over the steps to get a beginner up and running with OpenKCC something like this outline:
Sorry to skip the rest of the bullet points in the template, but I hope the issue is clear, if not, please let me know.
Switch away from the current built in animation controller to a code based animation controller so complex state transitions can easily be tied to a code based FSM and be more smoothly integrated with IK and version controlled as C# code.
May involve investigating how to properly manage blend trees via code as well.
Create basic tests for edit mode to provide full coverage of existing code base.
If some code paths or functions are no longer in use, remove them from the project.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.