godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.07k stars 69 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 1 year 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 1 year 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.

Ctrl32 commented 9 months ago

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

DDarby-Lewis commented 5 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 5 months ago

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

-S

sammonius commented 1 week 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