alexjhetherington / godot-character-controller-example Goto Github PK
View Code? Open in Web Editor NEWAn example implementation of a character controller, using move_and_collide
An example implementation of a character controller, using move_and_collide
low safe margin (e.g. 0.001) fails to handle some complicated intersection geometry, but otherwise works very smoothly
high safe margin (e.g. 0.01) handles complicated intersection geometry really nicely; but struggles with flat ground consisting of multiple colliders
My philosophy:
About the solution:
Not that it's too important, but I was going back through this today out of curiosity and figured you might want to know the references to your files here in this repo are invalid now on the website.
Hi, there. I've been trying out this controller in my project and I'm quite happy about it, it's working great, except for this one thing: sometimes I get stuck on door frames, as in the gif below. I am using Jolt physics, btw.
This seems related to the collision cylinder height, though. The cylinder in the gif below is 1.8 high and my doors are 2 meters high. I tried smaller cylinder sizes, and at 1.6 high I didn't have this issue anymore.
I recreated my door frames with CSG boxes just to see if they would behave the same as my trenchbroom geometry, and they did. To reproduce it, all I have to do is walk into the door frame and keep pushing W while it slides into the open space. Most of the time it won't enter the open space, like in the gif.
However, I tested this in your demo project and the behavior was a bit different, for some reason (maybe something I changed in mine). Instead of sliding like in the gif above, it gets stuck to the corners of the CSGBoxes. But this still seems related to the collision height, as lowering the cylinder height made it stop getting stuck (and I had no issues at all with the pillar on the right, in the picture below).
(My version of the demo project is attached below.)
I found two issues with jumping over things, which may be related to the stepping code. I added some boxes to the test map. My jump code is fairly simple, just add jump_force
to the desired_vertical_velocity.y
when space is pressed.
Jumping mostly works fine, except that when hugging an obstacle, pressing forward into it and jumping:
The second issue may disappear by changing the step_height
or the jump_force
. It seems to only happen under some circumstances, and with the current settings the red box is the only one with the right height for it to happen. But the first issue seems to be always there, except on smaller obstacles, like the white box.
Here's the demo project with jumping. It's a bit bigger because it already includes Jolt, and TBLoader, another test map and a few textures.
godot-character-controller-example-main.zip
The few changes I made to the code all have the comment # (skaruts)
, to make them easier to find, if needed.
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.