1
$\begingroup$

I have a bunch of running creatures and want to them to be instanced on very specific points, so I'm using some vertices as a base object with Instance on Points node. And I'd like them to be oriented on a tangent of a curve (blue arrow).

enter image description here

In my head I need to find a closest point on the curve for each clone and sample a tangent from that point. but.. Sample nearest takes geometry as input and everything else is confusing.

I've tried to go backwards: instance objects on curve, orient them on the curve orientation and then set positions to my vertices but obviously positions are set not in the same order as the objects are instanced on the curve so orientations are all over the place

enter image description here

The scene. Please send help. Thank you!

$\endgroup$

1 Answer 1

4
$\begingroup$

You have the right idea: sample the nearest point on the curve, get the tangent of that point, and then align the rotations of your instances to that vector. Let's see how we could manage that here.

First of all, just for convenience, I took the liberty to organize and simplify your setup. For example, I re-oriented the axes of your goblin figurine so it stands upright. If you don't wanna do that, you could also simply use a Transform Geometry node to do the necessary rotations inside Geometry Nodes:

enter image description here

enter image description here

As you've already pointed out, Set Position uses the indices of the points to place the instances, and that index order doesn't necessarily correlate with the order of the indices of the closest curve points we want them to align to, thus, there's no need to use Set Position at all—we can directly instance on the vertices. Rest of the setup we construct going backwards:

We want to sample the nearest point. Sample NearestPoint gets us the index of the nearest point to our vertices, and Sample Index enquires that point about a certain value—in this case a Curve Tangent so we can Align Euler to Vector. These two sampling nodes only work with meshes and point clouds though, not curves, so we need to convert Curve to Mesh first. However, mesh vertices do not have a Curve Tangent value, so to not lose that information, we use a Capture Attribute before the conversion, propogating those values from the control points of the curve to the points (vertices) of the mesh. We feed this captured attribute into the Sample node to enquire about it later in the tree. Since we're not instancing the goblins on the curve, we're not trying to match the number of control points to the number of vertices anymore so technically we don't need to use Resample Curve either, but more control points means more granular sampling of values, so resampling a decent amount is still desirable. Just using the Evaluated mode was satisfactory to me here, but you can use Count or Length to get slightly different results.

enter image description here

$\endgroup$
1
  • 1
    $\begingroup$ This is amazing — thanks for the explanation and your reply! The way attributes can be juggled around feels pretty confusing but little by little it starts to make sense to me $\endgroup$ Commented Jan 13, 2023 at 9:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .