godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.16k stars 97 forks source link

Add edge compensation for KinemeticBody 2D/3D collision shapes #3258

Open elvisish opened 3 years ago

elvisish commented 3 years ago

Describe the project you are working on

A first person shooter.

Describe the problem or limitation you are having in your project

When dropping off ledges using a capsule shape, the rounded edge is noticeable during lowering down. It didn't happen with games like Doom or Quake as they essentially used box colliders (Doom used a rectangle since it's a 2.5d engine).

Describe the feature / enhancement and how it helps to overcome the problem or limitation

Edge compensation simulates a cylinder shape (if using a capsule) when over an edge, it does not simulate this shape during any other time so as to be able to traverse terrain and slopes more reliably.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

image Normally, when a character is standing on an edge, it's collision shape will make contact with it. What edge compensation does is to lift up the capsule, simulating a cylinder shape.

If this enhancement will not be used often, can it be worked around with a few lines of script?

No, it would need to be part of KinemeticBody.

Is there a reason why this should be core and not an add-on in the asset library?

It would need to be part of the KinemeticBody core code.

Calinou commented 3 years ago

Related to https://github.com/godotengine/godot-proposals/issues/2751.

Do other game engines support this? To me, it seems like you should use a cylinder shape instead. Relying on the capsule's edges for stepping on stairs isn't a good idea as it's slow and causes unnecessary "bumping". Instead, you need to use one or more raycasts to step on stairs or use invisible slopes (clip brushes) for stairs. Using a mix of both approaches is quite common in practice too - this is how it's done in most Source games.

For smooth movement on terrain and slopes, a cylinder shape should work just fine (like an AABB, in fact).

elvisish commented 3 years ago

Related to #2751.

Do other game engines support this?

Yes, a couple of Unity asset controllers do in fact support this.

To me, it seems like you should use a cylinder shape instead. Relying on the capsule's edges for stepping on stairs isn't a good idea as it's slow and causes unnecessary "bumping".

For smooth movement on terrain and slopes, a cylinder shape should work just fine (like an AABB, in fact).

I wasn't sure if there'd be a down-side to using cylinders instead of capsules for terrain and such, it's good to know it shouldn't cause a problem.

use invisible slopes (clip brushes) for stairs

Really don't think this should be necessary (merely optional) at all in a modern game engine, although that is an issue for another proposal entirely: https://github.com/godotengine/godot-proposals/issues/2751

Also, this would be very useful for KinemeticBody2D where you'd want a capsule for slopes so the character doesn't levitate weird, but also falls straight down off an edge.

KeyboardDanni commented 1 year ago

It didn't happen with games like Doom or Quake as they essentially used box colliders (Doom used a rectangle since it's a 2.5d engine).

The way Quake addressed this problem was by extruding the collision shapes in the map at compile time three times, for different object sizes, and then simply performing raycasts at runtime to check for collisions. Of course, this is quite limited and wouldn't be a good fit for an engine like Godot. If anything, I'm curious how Unreal handles this.

Yes, a couple of Unity asset controllers do in fact support this.

Do you have any good examples of Unity asset controllers? How do they approach the issue?

elvisish commented 1 year ago

Yes, a couple of Unity asset controllers do in fact support this.

Do you have any good examples of Unity asset controllers? How do they approach the issue?

https://assetstore.unity.com/packages/tools/physics/character-controller-pro-159150

https://assetstore.unity.com/packages/tools/physics/kinematic-character-controller-99131

https://assetstore.unity.com/packages/tools/physics/character-movement-fundamentals-144966

There was one more but I can't remember what it was called as I haven't touched Unity in a couple of years 😄

KeyboardDanni commented 1 year ago

None of the controllers you linked here appear to have any edge compensation according to their WebGL demos. The third one does at least push the character off the ledge so they're not sinking/hovering in the air, but it also tends to throw the character away from the ledge.

elvisish commented 1 year ago

None of the controllers you linked here appear to have any edge compensation according to their WebGL demos. The third one does at least push the character off the ledge so they're not sinking/hovering in the air, but it also tends to throw the character away from the ledge.

I'm certain Character Controller Pro does, but since Godot supports box colliders it is pretty unnecessary to use capsules if you want boolean ledges.