Snap to tilted surface

I’m trying to snap a sphere on the z axis to the nearest plane. Getting some issues when the plane is being tilted (probably missing some maths with dot productions and whatnot)

snapto

ignore the rotation thing, not sure I need that at all.

Remember that normals aren’t rotations, they are unit vectors. You can convert vectors to rotations using the Align Rotation to Vector node. In this case, you can just use the target object’s rotation. Here I’m using the hit normal to get the distance to the center of the bounding box - It is half way in, hence the scaling by 0.5.

Another thing I’m doing is adding 50 to the object’s z coord to ensure larger “snap” range.

Good luck.

5 Likes

I’m gonna stare at this for the rest of the evening :slight_smile: This is really cool, thanks for that!

What if I only want to move the sphere on the z axis though? I had issues with using the bounding box when trying to isolate a single axis vs a non planar surface.

Hi dan,
here’s a little nodegroup that will calculate the intersection of an infinite large plane and a sphere:

This is what the “Plane Sphere Intersection” nodegroup looks like inside:

The Position input is the center of the sphere. The Location is a point on the Intersection Plane and the Normal is its normal. The Direction input defines in which direction you want to move the sphere at (for example on the Z-axis).
The Selection Output returns True if the sphere is intersecting with the plane / if some part of the sphere is behind the plane based on the defined Normal input:
image

Hope this helps!

Edit: Nevermind… didn’t read the part with the “non planar surface” :sweat_smile: sry!

3 Likes

Thanks, appreciate it! This works nicely. Took me a bit to figure out that it’s not doing anything cause I had no intersection going on :smiley: Without using a selection this is exactly what I was after. I knew I needed something with a dot product.

1 Like