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

feat: Add a hitboxFilter argument to raycast() #2968

Merged
merged 1 commit into from
Jan 9, 2024

Conversation

filiph
Copy link
Contributor

@filiph filiph commented Jan 9, 2024

Description

Adds a new argument callback to all raycast* methods that lets the user ignore hitboxes dynamically. The callback is called with every prospective hitbox, and the hitbox is only considered when the callback returns true.

This is faster, in the general case, than the current ignoreHitboxes aproach. And it lets the developer have dynamic rules about what the rays collide with. (For example, a line-of-fire raycast should take friendlies into account, but could easily ignore other enemies that get in the way.)

Checklist

  • I have followed the Contributor Guide when preparing my PR.
  • I have updated/added tests for ALL new/updated/fixed functionality.
  • I have updated/added relevant documentation in docs and added dartdoc comments with ///.
  • I have updated/added relevant examples in examples or docs.

Breaking Change?

  • Yes, this PR is a breaking change.
  • No, this PR is not a breaking change.

For people who just use raycasts, this is not a breaking change.

People who extend CollisionDetection will need to support the new argument. I'd say this is pretty rare but not unheard of.

If you have your own custom collision detection logic (a class implementing or extending Flame's CollisionDetection), you'll have to update its three ray* methods. Add the new argument to the base raycast() method and make sure that the ray actually only collides with hitboxes that return true from hitboxFilter(). The other two methods (raycastAll() and raytrace()) will, in most cases, just call raycast(), so just make sure you pass the argument.

Related Issues

Closes #2966

Adds a new argument callback to all `raycast*` methods that lets the user ignore hitboxes dynamically. The callback is called with every prospective hitbox, and the hitbox is only considered when the callback returns `true`.

This is faster, in the general case, than the current `ignoreHitboxes` aproach. And it lets the developer have dynamic rules about what the rays collide with. (For example, a line-of-fire raycast should take friendlies into account, but could easily ignore other enemies that get in the way.)

Fixes flame-engine#2966.
Copy link
Member

@spydon spydon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm!

@filiph
Copy link
Contributor Author

filiph commented Jan 9, 2024

Thanks! Just a reminder that I don't have commit rights here so you'll have to land this yourself when you're happy.

@spydon
Copy link
Member

spydon commented Jan 9, 2024

Thanks! Just a reminder that I don't have commit rights here so you'll have to land this yourself when you're happy.

Yep, only Blue Fire has merging rights here.

@spydon spydon merged commit d7c53e2 into flame-engine:main Jan 9, 2024
8 checks passed
@filiph filiph deleted the feat/raycast_filter branch January 9, 2024 12:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Let raycast dynamically ignore some hitboxes
2 participants