Need a little help from someone who's good with vectors and transform spaces

Hello, I’m currently building a little spline tool to help me place large crop fields in the environment with some useful controls for my purposes. Gist of it is, I have a spline, I move the points in XY and they snap to a fixed height on Z relative to the ground, and crops get spawned within the spline according to values I set for Crop Spacing, and Row Spacing. Here’s quick video to illustrate the idea probably better than words:

The key aspects here - in construction script, I get the bounds of the actor containing the spline, and then use that information to generate a single line of X-axis transforms for the instances, like so:

Imgur

I then use that first line and the bounds Y extent, to add and subtract along Y for each existing instance, to generate all the rest of the transform locations, like this:

Imgur

I then line trace to put all those transforms at terrain level, and then check if each transform is within the bounds of the spline curve. If it is, I add an instance to the HISM.

This works pretty well as you can see in the video, except for the fact that it’s all happening in world space and only functions properly if the spline actor has no rotation.

However I want to be able to define the rotation of the crop field. I’m having a very hard time figuring out where and how in the above sequence I need to adjust the transforms in order to get this to work as it does in the video, but with the ability to either rotate the spline actor itself, or define a rotation float variable, or basically some method to get the same behaviour but the entire thing being able to rotate so I can angle the field relative to roads and other scene objects easily.

If you need any more information in order to help I’m happy to provide it. Would love to figure this out and I’m sure someone who’s better than me with this stuff will have the right idea for me to go down… hopefully :slight_smile:

I know exactly what you mean. I’ve been working on procedural foliage tools for placement on spheres.

I found, that rather than trying to figure out what transform space you’re in ( nightmare ), it’s easier to do two things:

  1. Make sure you don’t assume the actor is level. So, don’t trace down for the ground, for instance, trace in the direction of the actor up vector ( * -1 ).

  2. There’s always a safe place you can add local rotation to the HISMs, without trying to figure out any sweaty maths. Amoung other things, I found:

2a) The opposite of the ‘down’ vector, you can get the correct instance positioning using RotationFromXvector, or some sort of LookAtRotation.

2b) Combining rotators is good, but the order really matters. One way around will give you rubbish.

2c) Placing the instance with the correct transform doesn’t work, as far as I can tell. But it’s ok, the workaround is just to place them, and then correct with UpdateInstanceTransform.

Thanks man, that was the tip I needed.

I had to rework a couple of things but now I’m spawning the instances in a square according to the furthest bound extent of either axis, applying rotation via float variable to the whole HISM and then culling whats outside the curve after that. Working pretty nice, thanks for the advice.

Much simpler way of doing it!

Your advice on the trace direction is also a good point, will tweak that.