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

Bouncing Lasers limitations and bug #10

Open
BenjaminOrenstein opened this issue Jul 22, 2024 · 7 comments
Open

Bouncing Lasers limitations and bug #10

BenjaminOrenstein opened this issue Jul 22, 2024 · 7 comments

Comments

@BenjaminOrenstein
Copy link

As is, we have to choose between Lasers bouncing off of objects and ignoring objects. What if I want for lasers to bounce off of mirrors and collide with walls? As is, it seems like that's not possible.

I had assumed that this limitation was as intended, however this creates another issue:

Imagine this scene:

[Mirror] [Block] <=[Laser]

Mirror is part of the group "reflects" which Lasers bounce off of. The Laser sees that it doesn't bounce off the block. The displayed ray, however, renders it's full length and does not collide with the mirror/wall.

See attached images. One of them shows what happens when the laser collides with something in a bounce group, one shows what happens when it does not.

Reflects No-Reflect

I've made some progress on a fix for myself, but I've gotten a little lost in your code trying to figure out the logic for adding points to the line. Would love to see an update that fixes this, but I will continue working on it on my end and post an update if I find a full fix.

@BenjaminOrenstein
Copy link
Author

BenjaminOrenstein commented Jul 22, 2024

I'm reading this back and it's maybe not the clearest - let me know if I need to re-explain or if the provided images are helpful enough for you to understand the bug!

EDIT: And to clarify this is only an issue if a bounce group is set - otherwise it works as expected. See image:

reflection working

@Dark-Peace
Copy link
Owner

Mmh ok, I'll see what I can do when I have time

@Dark-Peace
Copy link
Owner

I think I fixed it. I'll update it on itch later but putting the line

if not can_bounce_on($RayCast2D.get_collider()): break

After the line

if bounce_cooldown > 0:
  await get_tree().create_timer(bounce_cooldown, false).timeout

Instead of at the beginning of the loop, should fix it

@BenjaminOrenstein
Copy link
Author

This fixes the collision detection but does not fully fix the updates to Line2D/visuals as seen in the screenshot below. Note that the laser is currently colliding with the box but the not the wall behind it (which is as intended, so it does fix that part).

no-reflect-update

Also, note that something in your current update from a few days (week?) ago breaks reflection angles for me. I did some weird stuff to get laser rotation working in my project and so it may be a result of that and not your update. I didn't try diagnosing and just reverted back, so I don't have images to demonstrate but it may be worth running some tests to make sure that the angles of reflection are as intended. I can create an issue for that sometime this week and gather more info, but first I want to make sure that it isn't just a result of you properly fixing something in a way that breaks something I'm doing.

@BenjaminOrenstein
Copy link
Author

BenjaminOrenstein commented Jul 29, 2024

I updated the following to check if the last cast was colliding:

# if last laser segment doesnt hit a wall, still draw it
if can_end_midair and (!$RayCast2D.is_colliding() and max_while < bounce_count+1 or points.size() < 2):

I haven't fully tested this and I'm not sure if this creates any other issues, but it fixes the issue with updating Line2D properly.

@Dark-Peace
Copy link
Owner

Ok thx
For the reflection angles, it's very tricky. Each time I think I got it right, there's a new case found where it's wrong, then fixing it breaks the previous cases,...

@BenjaminOrenstein
Copy link
Author

Yes, reflection angles are an implementation nightmare with how Godot handles rotation/positions. Everything is very inconsistent and it's hard to know how things are intended to be used. To be honest, I purchased your tools because of the difficulties that I have had with my own implementation. I'm new to godot and figured my time was better spent elsewhere. I may take closer look at how rotation works in the future and let you know if I find anything worthwhile.

All that said, I currently have a functioning version of your project and am very happy with it. Thanks for taking care of the issues I've encountered as they present themselves! This projects existence has saved me a ton of time!

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

No branches or pull requests

2 participants