#Find all nodes in a line
21 messages · Page 1 of 1 (latest)
I believe https://docs.godotengine.org/en/stable/classes/class_raycast2d.html sounds like what you're looking for?
Inherits: Node2D< CanvasItem< Node< Object A ray in 2D space, used to find the first CollisionObject2D it intersects. Description: A raycast represents a ray from its origin to its target_position ...
Is there a way for it to keep going? From what I've read it stops at the first body
Although that page did lead me here: https://docs.godotengine.org/en/stable/classes/class_shapecast2d.html#class-shapecast2d
maybe this is what I need
Inherits: Node2D< CanvasItem< Node< Object A 2D shape that sweeps a region of space to detect CollisionObject2D s. Description: Shape casting allows to detect collision objects by sweeping its shap...
If you don't care about the order of the objects ( which gets hit first) you can use an area2d to detect all objects
With a box collision shape with long width and small height it's similar to a line
Otherwise you would have to shoot multiple raycasts or shapecasts, adding the previously hit object to a growing exception list
I hadn't even thought of using a thin area2d 🤦♂️ but you do mention a good point about exception lists. Since I only want the line to affect each brick once, is there an easy way to keep track of this for an area2d?
It's still possible to do the detection for only one frame so each brick is only affected once with an area the only thing really is that you can't determine the order of the bricks in the line that way
At least not cleanly or precisely
The order won't matter which is fine
And yeah the lines will be short lived since each ball can hit the power up, 1 frame might be too short but it's a starting point
I'll give it a try with both shapecast2d and area2d thank you for the suggestion
a few things to keep in mind:
areas (and ray/shapecast) nodes need 1 physics frame to update if you move/rotate them for the new detections to be updated
with raycasts you can circumvent that by force updating them, which is especially handy when going for the multiple hits exception list approach
btw, heres an example: http://godotfaq.rf.gd/doku.php?id=cast_ray_through_multiple_objects
if you cant wait one frame and want to use the area approach, or use a ray/shapecast but without nodes you can do a "theoretical" check against the current space using intersect_shape() / intersect_ray()
https://docs.godotengine.org/en/stable/classes/class_physicsdirectspacestate2d.html#class-physicsdirectspacestate2d
Inherits: Object Inherited By: PhysicsDirectSpaceState2DExtension Provides direct access to a physics space in the PhysicsServer2D. Description: Provides direct access to a physics space in the Phy...
I like the look of that example. With that I could get the full list of nodes, update their hp, and do an animation very cleanly I think
And the animation would be decoupled from the actual hp logic which is nice
@reef sable Quick question regarding ray casting. It seems like even though I have a position and target position set, the angle of the ray is off (I have visible collision shapes turned on to see this). Do I need to set a rotation even if I'm telling it where to go?
I would expect that since the y positions of the position and target position are the same it should just be horizontal