Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a ConeShape primitive 3D collision shape #610

Open
issork opened this issue Mar 21, 2020 · 16 comments · May be fixed by godotengine/godot#96288
Open

Add a ConeShape primitive 3D collision shape #610

issork opened this issue Mar 21, 2020 · 16 comments · May be fixed by godotengine/godot#96288

Comments

@issork
Copy link

issork commented Mar 21, 2020

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
Copy link

Arrow-x commented Mar 25, 2020

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

@hhyyrylainen
Copy link

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
Copy link

jesperkallunki commented Jun 5, 2020

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 😊.

@Calinou
Copy link
Member

Calinou commented Mar 24, 2022

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.)

@Calinou Calinou changed the title Expose the ConeShape from Bullet Add a ConeShape primitive 3D collision shape Jul 21, 2022
@gebba

This comment was marked as off-topic.

@Calinou
Copy link
Member

Calinou commented Nov 7, 2022

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

@SimonHeggie
Copy link

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
Copy link
Member

Calinou commented Apr 28, 2023

-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
Copy link

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

@DDarby-Lewis
Copy link

DDarby-Lewis commented Jan 23, 2024

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

This comment was marked as off-topic.

@sammonius
Copy link

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

@LRJiao LRJiao linked a pull request Aug 29, 2024 that will close this issue
@aaronfranke
Copy link
Member

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
Copy link

jrouwe commented Aug 31, 2024

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
Copy link

jrouwe commented Aug 31, 2024

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
Copy link

jrouwe commented Sep 2, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.