godotengine / godot-proposals

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

ShapeCast2D & 3D: Collider-Related Functions' 'Index' Parameter Should Default to 0 #11270

Open batbrain55 opened 3 days ago

batbrain55 commented 3 days ago

Describe the project you are working on

A first-person shooter.

Describe the problem or limitation you are having in your project

I'm using ShapeCasts for various stuff, like sightlines and checking if I have enough space for uncrouching.

For the overwhelming majority of my use cases I don't care about any colliders other than index 0. Despite this, I still have to specify index 0 in the 'get_collider'/related functions, because otherwise my code won't run. It's kinda annoying, especially since RayCasts, which have similar functions, don't have an index. I understand why this is the case, but it causes me a sort of jet-lag when I switch between the two node types.

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

If you don't specify an index number when calling relevant functions on a ShapeCast2D/3D, it should default to index number 0.

It'd be a nice quality-of-life feature that'd just make it overall smoother to use ShapeCasts. For a lot of cases it'd make it trivial to use the exact same code for a ShapeCast that you could for a RayCast just by switching the node type you're instantiating and making no other changes, because their similar functions could be called identically with no worries. No need to add/remove zeroes.

Additionally, it'd have zero chance of breaking currently-existing scripts, because ShapeCast calls that specify index 0 will still work just as they always have.

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

All index-related functions in ShapeCast2D/3D nodes have a default value for the index parameter of 0 if you don't specify it yourself and just leave the parameter field blank.

These functions are:

For example: ShapeCast.get_collider(), with no arguments, would assume an index of 0.

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

It wouldn't be worth it compared to just specifying the index as 0 each time. As I mentioned earlier, this is a quality-of-life feature that's meant to let you not have to think about the index unless it's relevant to whatever you're doing.

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

This change would be trivial to add and would make ShapeCasts much smoother to use straight out of the box.

Calinou commented 3 days ago

On the other hand, the downside of making the parameter optional is that it would make code less explicit. This can be a problem if you add new colliders later on and expect get_collider() to work if any of these are colliding, not just index 0.

batbrain55 commented 3 days ago

On the other hand, the downside of making the parameter optional is that it would make code less explicit. This can be a problem if you add new colliders later on and expect get_collider() to work if any of these are colliding, not just index 0.

This would be alleviated with a note in the documentation that makes it very clear what happens when you don't specify the collider number.