I’m still very new to the BP system, so, please pardon my noobness.
I’m doing a tutorial on making procedural content. The idea is pretty simple, just spawn a random mesh in various positions when you drag it into a level…
What my question is; how do I just make it randomly place objects on the X and Y axis while leaving Z at 0?? (I want the bushes to snap to the ground).
First: Ground may be at a place different than 0. Using raycasts is generally better.
Second: It’s easier to multiply (not cross!) by the vector (1, 1, 0) which avoids converting back and forth.
You can also drag off vectors and type “break vector” or drag off floats and do “make vector”. This way you can do a break transform on the random unit vector and connect the X and Y axis but not the Z axis to a Make Vector.
The line trace you’d be looking for is LineTraceByChannel
To explain what that method is and why to use it, say you have a terrain where the elevation increases and decreases. Suddenly, your bush blueprint won’t work - since the Z-axis changes. So what you’d do is instead of spawning bushes at random X by Y locations, you would - in your construction script so you can see it in-editor - instead use those locations to start a line trace down.
You’d make the line trace start where the bushes are spawning now, and raise your actor into the sky. Make the end of the line trace the start location - 0,0,10000. Then, off the hit location, that is where you spawn your bush.
To explain what this will do, in-editor as you drag your bush BP around, it will do line traces down from random locations. This will create a line to see if it hits anything. When it hits the ground, it will spawn the bush there. This way, you can just drag this around and not have to worry about height at all!
You need to actually pay attention to the OutHit result, which will tell you where the ground actually is.
You need to make the start vector take the X and Y of your “initial location” – as it is, you’re just tracing from the origin.
You need to make the end vector be negative Z, so it’s below the ground.