Today I was trying to wrap my head around the raycast node in geometry node. My plan was to create a plane that can rotate freely on the 3 axis, parent this plane to the camera, and to raycast on this plane another geometry, that gets flattened according to the rotation of the plane. (ie, the plane should act a bit like a frame that captures the geometry according to the prospective of the plane itself)
But I didn’t even manage the first step lol. Why is only one point moving?
The problem I think is the ray direction: I thought that obtaining the difference of the two position would have worked, it should be the vector measuring with the right direction and lenght connecting position A and B (from the screenshot it’s not clear but I used “position of icosphere”-“position of plane that should work as the raycast surface”), but… Well, I don’t know if it’s the wrong approach or if I am using the “Capture attribute” wrong!
Can somebody help me understand what I’m doing wrong please?
This mostly has to do with incorrect use of Position node.
To find a direction you need to subtract locations of source and target objects. But position node reads position of individual vertices in those objects. You can see that it’s a field of values by the diamond shape of the output socket and a dashed lines.
I wouldn’t try to guess why exactly it gave the result it did… suffice it to say, it probably won’t return meaningful results like that.
What you need is Location of the objects themselves - it’s a single value (round sockets and solid lines).
Here we can look at two cases.
First, simple one. Let’s say Plane and Icosphere are supposed to be two separate Objects with Icosphere being modified by GN, it gets pretty straightforward.
We can use Object Info node to get Location of the plane object (of its Origin Point) relative to modified object. That will be the direction vector.
Second, the one in your example, where both object are created from within the GN tree. Here, both objects are created at the center of coordinate system at (0,0,0). But, you then translate them with a vector, right? Well that vector is the Location for our purposes. Assuming you don’t move the sphere from its starting location and only translate the grid object - that translation vector can be used as direction.
Thank you so much! It works and it totally makes sense, I feel quite dumb now.
I still wonder how can rotation (maybe it doesn’t at all and it’s my ignorance in vector math) can influence the whole setup, I will do some test… thank you again for your thorough explanation!
Right now it doesn’t influence the thing - the points just go in the direction of the plane location, no matter how the plane is rotated.
Provided, they hit the surface at all, of course - since if the plane is at a too harsh an angle relative to the sphere, its profile will become smaller and raycast will start to miss.