# How to prevent instances from going beyond a curve length?

#### When instancing object on a curve, the first and last objects go beyond the curve length, like in this picture: If I adjust the position of the first and last point, it creates a new problem where the instances are not evenly distributed: ## EDIT:

The answer from @vajtus solved my problem.

I just added some nodes to his answer so this setup can be used in more situations. This way if you add any Geometry still should work.  In your node setup, you are just shifting the first and last point after it has been evenly distributed by the Resample Curve node, therefore it is not evenly distributed any more.

The key is to shorten the curve before you resample it but I also recommend to use the Trim Curve node instead of selecting and repositioning the endpoints. This way you don't have to worry about which way to move them.  • And maybe use something like this to calculate the half-length automatically: i.imgur.com/NaZRJAX.png Jan 11 at 20:42
• Thanks. This do what I was aiming for. Jan 11 at 22:25 The Map Range Node and Attribute Statistics Node are the key nodes. The Map range is used to fit values within the desired range, while the Attribute statistics will let you know a set of values from the given field. The Min and Max values in the From sections on the Map Range Node should come from the min and max values from the attribute statistics (Remember to set it to Instances). I arrayed them in the Y-axis, so I separated the position and only edited the y values. The To Min value should be half the cube's size. This is because the cube is instanced from the center, while the goal is to start from the exact beginning. So we add the other half to accomplish the full size of the cube. Since we also want the end of the last cube to be at the exact end of the line, we simply subtract half its size from the length of the curve to do the opposite of what we did to the first cube. This becomes the To max value. I recombined the vector with edits only on the Y-Axis and used it for the Set Position Node. I hope this makes sense.

Here is the node setup: 