godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.17k stars 98 forks source link

Add a ConeShape primitive 3D collision shape #610

Open issork opened 4 years ago

issork commented 4 years ago

Describe the project you are working on: This is a project I came up with while thinking of use cases for such shapes, since I already opened my PR to solve this. I came across godotengine/godot#2138 and godotengine/godot#17252 and decided to expose it myself.

A very simplified flight game in which the player steers a plane.

Describe the problem or limitation you are having in your project:

The crowns of the trees in this game would be cone shaped. Since I need more precise collisions than cylinders or other shapes for the plane to be able to collide with the trees accurately, I can not use any of the other internal collision shapes.

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

Exposing cone shapes would ease the access to this shape and would completely solve this problem.

Describe how your proposal will work, with code, pseudocode, mockups, and/or diagrams:

See my PR in godotengine/godot#37199 which exposes it.

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

Yes, one could generate a cone shape from the mesh of the tree crown or write a script that generates it. This would however not be as optimized as bullets cone shape.

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

Yes, as this should belong to the already existing collision shapes. It is however possible to implement this as an add on, but I'm not sure if this shape can then be selected in the CollisionShapes 'Shape' drop down menu.

Arrow-x commented 4 years ago

I second this, this a very useful shape, and it is already there in Bullet, I see this as an absolute win

hhyyrylainen commented 4 years ago

I just tried converting over some code to Godot that used Bullet directly, and I was very surprised to be unable to find a way to make a cone collision shape.

jesperkallunki commented 4 years ago

I started to work on an Area3D field of view for ai and was looking for cone/pyramid CollisionShape but found none in the dropdown menu. This should definitely be a basic shape :blush:.

Calinou commented 2 years ago

Note that Bullet will no longer be included in core in Godot 4.0. Therefore, a cone collision shape needs to be implemented in GodotPhysics before this can be considered. (This is absolutely required, as we can't implement a feature in 3.x only to remove it later in 4.0.)

gebba commented 2 years ago

Just ran into wanting this shape as well, for the exact same use case as @jesperkallunki mentioned. Thought I'd add my voice to this to maybe make it happen :)

Calinou commented 2 years ago

@gebba Please don't bump issues without contributing significant new information. Use the :+1: reaction button on the first post instead.

SimonHeggie commented 1 year ago

It's also useful to discuss some ways in which this could be useful. This is from an artist's perspective, but I have some programming and game design examples primarily:

-Cones can simulate NPC point of view collision. This is far more predictable and simpler than working with raycasts, and can be visualized to the player for instance in stylized top down stealth games, or where the NPC can only see by torch light.

-Work well both for collision and aesthetics of spike traps

-Achieve simple spotlight effects when given a transparent glowing shader

-Cones can even achieve some simple architectural looks:

-Can be the base if inverted or else the roof of a medieval turret -Becomes Egyptian pyramid when 4 sided -Good for aesthetically gothic maps like bowser's castle which is often lined with vertical spikes.

Calinou commented 1 year ago

-Cones can simulate NPC point of view collision. This is far more predictable and simpler than working with raycasts, and can be visualized to the player for instance in stylized top down stealth games, or where the NPC can only see by torch light.

Instead of using collision shapes, you probably want to use an analytic approach to detecting view sight (using the dot product). This way, you can determine how quickly an enemy should notice the player based on distance from the player, but also based on the angle relative to the player. A player that is 90 degrees on the side should generally take longer to be noticed that a player that is dead center in the enemy's eyes.

By contrast, collision shapes are an "all or nothing" thing and don't give you any context other than "the player is in sight".

-Cones can even achieve some simple architectural looks:

You can use trimesh collision for static level geometry, so it's not strictly required here.

Extner32 commented 1 year ago

This would definitely be useful for creating vision cones for enemies.

DDarby-Lewis commented 10 months ago

A better implementation than a cone might be something like a capsule collider but with spheres of different radii at the ends. This is like a soft cone and could be implemented efficiently as a sphere along a line with the radius a function of distance. It might be more efficient than a cone having simple maths - but it would also be less glitchy since it has rounded ends not a point.

SimonHeggie commented 10 months ago

That's a good idea, and I agree with that method 😀

-S

sammonius commented 5 months ago

I agree, there should be the same options that are availiable for the cylinder mesh, with top and bottom radii. There's a lot of cases where this would be really useful. I ran into this issue while trying to make collision shapes for this lamp (specifically the top part): image

aaronfranke commented 3 months ago

Another option is to allow the cylinder shape to have different top and bottom radiuses. This is what KHR_collision_shapes does in its cylinder definition: https://github.com/eoineoineoin/glTF_Physics/blob/master/extensions/2.0/Khronos/KHR_collision_shapes/schema/glTF.KHR_collision_shapes.shape.cylinder.schema.json

This would mean that you can make a cone by using a cylinder with one of the radiuses set to zero. However, I am not sure how common it is to need tapered cylinders.

Also we should get @jrouwe involved in this discussion. What is the best way to represent cone physics shapes in Jolt? Is it just a convex hull approximation? Alignment with Jolt may be helpful to drive a decision here.

jrouwe commented 3 months ago

I don't think it is too difficult to add a tapered cylinder shape like the KHR definition above.

Right now, you'd need to create a ConvexHullShape where the base has at most 16 vertices.

jrouwe commented 3 months ago

B.t.w. looking at the pull request: I think a tapered cylinder shape would be better than the cone shape that is implemented in the PR since it is more flexible.

jrouwe commented 3 months ago

The tapered cylinder shape has been merged into Jolt, so it should be possible to make an implementation in godot-physics+godot-jolt for this feature now.

cc @mihe so you know what may be coming.