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

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

Open
batbrain55 opened this issue Nov 30, 2024 · 2 comments

Comments

@batbrain55
Copy link

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:

  • get_collider
  • get_collider_rid
  • get_collider_shape
  • get_collision_normal
  • get_collision_point

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

Calinou commented Nov 30, 2024

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

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.

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

No branches or pull requests

2 participants