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

intersect_ray that returns multiple results #14608

Closed
supagu opened this issue Dec 13, 2017 · 11 comments
Closed

intersect_ray that returns multiple results #14608

supagu opened this issue Dec 13, 2017 · 11 comments

Comments

@supagu
Copy link
Contributor

supagu commented Dec 13, 2017

I am using intersect_ray for screen picking. The problem I have is that I don't just want the first object the ray hits, but I want them all, sorted in an array by distance from the start so I can iterate over them and determine which one to pick.

I have to work around this at the moment by doing multiple raycasts and using the exclusion list until nothing more is detected. Obviously this is going to be slower than a singular raycast that would return multiple results.

@Zylann
Copy link
Contributor

Zylann commented Dec 13, 2017

Maybe you could use intersect_shape with a LineShape, though I'm not sure in which order the hits will be (though they can be sorted easily with array.sort_custom)

@eon-s
Copy link
Contributor

eon-s commented Dec 13, 2017

@Zylann a segment shape, not line.

And ray must return only one result because that are rays for.

@supagu
Copy link
Contributor Author

supagu commented Dec 13, 2017

so Zylann's approach is the legitimate/proper way to do what I want?

@supagu
Copy link
Contributor Author

supagu commented Dec 25, 2017

I stepped through the engine code and noticed that the engine does most of the work already for this.
The difference between a ray_cast and intersect_shape is that intersect shape does not return the intersect point and normal.

So having a method like ray_cast that returns an array of hits I is still very helpful!

@eon-s
Copy link
Contributor

eon-s commented Dec 26, 2017

@supagu
Copy link
Contributor Author

supagu commented Dec 26, 2017

3d shapes? Or just 2d shapes?

@eon-s
Copy link
Contributor

eon-s commented Dec 26, 2017

2D shapes, 3D do not have that option.

Maybe PhysicsServer/PhysicsDirectSpaceState can add/expose some extra functions using Bullet, I think it is possible to do something similar to collide_and_get_contacts with it.

@reduz
Copy link
Member

reduz commented Dec 26, 2017 via email

@supagu
Copy link
Contributor Author

supagu commented Dec 26, 2017

Yea that's what i have been doing to hold me over.

@jakeonaut
Copy link

The dirty solution of using a while loop and adding objects to the exclude list is currently not possible if your ray ever intersects a GridMap due to #27282

@Calinou
Copy link
Member

Calinou commented May 27, 2020

Feature and improvement proposals for the Godot Engine are now being discussed and reviewed in a dedicated Godot Improvement Proposals (GIP) (godotengine/godot-proposals) issue tracker. The GIP tracker has a detailed issue template designed so that proposals include all the relevant information to start a productive discussion and help the community assess the validity of the proposal for the engine.

The main (godotengine/godot) tracker is now solely dedicated to bug reports and Pull Requests, enabling contributors to have a better focus on bug fixing work. Therefore, we are now closing all older feature proposals on the main issue tracker.

If you are interested in this feature proposal, please open a new proposal on the GIP tracker following the given issue template (after checking that it doesn't exist already). Be sure to reference this closed issue if it includes any relevant discussion (which you are also encouraged to summarize in the new proposal). Thanks in advance!

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

8 participants