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

fix: Ray should not be able to escape CircleHitbox #3341

Merged
merged 2 commits into from
Oct 14, 2024

Conversation

spydon
Copy link
Member

@spydon spydon commented Oct 13, 2024

Description

A raycasted ray should not be able to escape a CircleHitbox if it originates from inside of it (or on the edge and has a direction inwards).
Fixes: #3333

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.

Related Issues

// of the circle and then directly intersecting and causing the reflecting
// ray to go in the wrong direction.
_temporaryOrigin.setValues(
ray.origin.x + ray.direction.x * 0.00001,
Copy link
Member

Choose a reason for hiding this comment

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

should we put that into an epsilon?

Copy link
Member

@luanpotter luanpotter left a comment

Choose a reason for hiding this comment

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

Curious though what changed that caused this to break? And couldn't it be that the point started in a "good" place but when you add the small epsilon it ends in a "bad" place?

@spydon
Copy link
Member Author

spydon commented Oct 14, 2024

Curious though what changed that caused this to break? And couldn't it be that the point started in a "good" place but when you add the small epsilon it ends in a "bad" place?

It can happen, but it's very unlikely since the epsilon is so small. So the problem was that it properly calculates the first ray, but then it's calculating what the reflection ray will intersect and since its origin is straight on the edge of the circle sometimes the origin point was counted as the intersection, so we add a small vector to origin with the same direction as the ray to "get out" of the origin.

@spydon spydon merged commit 7311d03 into main Oct 14, 2024
8 checks passed
@spydon spydon deleted the fix/ray-should-not-escape-circle branch October 14, 2024 06:16
luanpotter pushed a commit that referenced this pull request Oct 15, 2024
A raycasted ray should not be able to escape a `CircleHitbox` if it
originates from inside of it (or on the edge and has a direction
inwards).
Fixes: #3333
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.

raytrace outside of circle?
4 participants