How to make raycast node that collides with bodies but go through them to end?
How to make raycast that collides with bodies but go through them to end (3D)?
Hramzhuk go through them to end
What does this mean?
- Edited
Megalomaniak When raycast collides with body he stops, right? i want he to keep going.
You can set collision mask layers. But I think you'll need to shoot 2 ray casts, as the whole point is that they collide.
- Edited
I would find a raycast like this usefull to get a group of objects that are hit at once. They could be put an array or list to do with as we please. It would be more efficient than casting lots of rays.
If you are basing a lot of your logic on this, there are other methods you could use. Like creating a long thin collision body and checking for overlapping bodies or areas. The most common use case for a ray cast would be to find the first collision. Can you explain what you are doing that you need more than one result?
- Edited
Or create a path.
A ray is not a line. A ray has a beginning and an end and is meant to report the first collision in between, plus some information about it, if any. But you can create a path of rays, a new ray at every collision point of the previous ray. But you need to specify exactly the conditions when to end the path. And doing this repeatedly may be slow in GDScript.
Without knowing what you want to achieve, which Godot version, 2D or 3D, what the scene is like, it is hard to answer more specific.
Pixophir A ray is not a line. A ray has a beginning and an end
Well, technically, in mathematics, a ray only has a starting point and a direction (it goes on to infinity). But in the context of computers, obviously you would not want infinite physics calculations. So, in practice, it has to be bounded, but you can think of it as a ray, within the bounds of what you are checking.
- Edited
cybereality Well, i'm making fruit ninja clone, and i need to make combos (so, you can slice multiple fruits at once). How it sayed in title, i'm using 3D. I just find, that raycast will be good to detect fruits.
The easiest way would be to use a collision shape. Though it's not possible to resize collision shapes while the game is running. You can do something with the custom Geometry class, that might be the best for a Fruit Ninja game. https://docs.godotengine.org/en/stable/classes/class_geometry.html
Doesn't Godot have plane/box and plane/sphere collision tests ?
That'll simplify things, because the swing of the blade could just be a plane, then, and collision test against a bounding sphere in a limited distance is trivial.
Slicing the sphere into two is another thing, though.
You can use the function segment_intersects_sphere
in Geometry, as long as the objects are close to spherical. But it still only checks one sphere at a time. Though these functions are fast, so calling them in a loop for 20 or even 50 objects should be no problem.