Beginner Question: Finding a random point on a line trace

I read somewhere someone offering this as a solution for random spawning of actors, I can’t find the example for the life me. My goal is to spawn actors randomly from a line trace originating from a character inside a static mesh building. Guards inside a castle’

I know one node should be a random float in range connected to a make a vector X, but how do i constrain that to a line trace?

Can someone show me an example that would work with 10+ actors spawning at the same time?
My vector length is about 1000

this is me guessing

You’re trying to spawn creatures at random along a line segment? That’s pretty straight forward… Here are the things you already should know:

The start vertex

The end vertex

The length of the segment pseudo-code (end - start).Length()

Are there any obstacles blocking the line segment? To find out, this is where you would use the line trace. Look at the hit result and see if there are any hits.

Now, you can generate ten random numbers between 0 and the segment length. These will be the spawn distances from the start vertex.

Next, we need to find the actual spawn positions in 3d space along the line segment. This might be the part which confuses you. You have to do SegmentEnd - SegmentStart to get a vector which has an origin at [0,0,0]. The direction of this vector will be the same direction as your segment. To get the LOCAL spawn position along this vector: Normalize this vector, then multiply it by the random numbers you generated. This is a randomly scaled position along the local vector. We’re not done yet. Now, you have to translate this position from local space to world space by adding the SegmentStart position to the randomly generated point. Now, this point is in 3D space along the line segment.

We’re still not done though! The actual spawn position may not exactly be on this line segment. If your terrain has a valley or a hill, you want to spawn your creature along the contour of the terrain along this line. To do this, you do another line trace from a high position (spawnpos + (0,0,1000)) to a reasonably low position (spawnpos - (0,0,1000)). Find the intersection point – this should be your terrain or some other object. This is the final spawn position for your creature.

Let’s say you have the vector [5,0,0].

A vector has a direction and a magnitude.

The direction is a line starting at the origin [0,0,0] and going to [5,0,0].

The magnitude is the length of the vector, which in this case is 5. The magnitude of the vector is disconnected from its direction, so no matter what direction it faces, its length will stay the same. The magnitude/length of a vector is always measured as its distance from [0,0,0].

I this case, if we normalize [5,0,0], it becomes a unit vector of [1,0,0]. This is now a direction vector, with a magnitude of 1. Notice how we can change the magnitude of the vector without changing its direction? We take advantage of this to get a random point on your line.

We can now take this unit vector and multiply it by any number we choose – let’s say 15.87. Now your vector becomes [15.87,0,0]. It retains its direction, but is now much further from the origin [0,0,0].

In your game, you’re going to be working with positions which are not at the origin. These are points in world space and you’re going to be working relative to them. To work with vectors, you need to convert these world space coordinates into local space coordinates – this just means you’re translating the origin to [0,0,0] so that you can use vector math.

Example: You have point A at [1,2,3] and point B at [6,7,8]. If you connect A to B, you get the line segment AB. This line segment has direction and magnitude, so it can be used as a vector. To get the line vector, you would subtract point B from point A: [6-1,7-2,8-3] => [5,5,5]
[5,5,5] has the same direction and magnitude as line AB, but now its in local space because we shifted Point A such that it is centered on [0,0,0], and point B is on [5,5,5]. Now we can do vector operations on it! When we’re done, we shift it back by adding point A back into it.

I am confused with vector origin vs vector length

http://i.imgur.com/neUzWA8.png

Confused with vector length vs vector origin,

http://i.imgur.com/neUzWA8.png

I got your response in my inbox accidently deleted my comment, thank you again

"Let’s say you have the vector [5,0,0].

A vector has a direction and a magnitude.

The direction is a line starting at the origin [0,0,0] and going to [5,0,0].

The magnitude is the length of the vector, which in this case is 5. The magnitude of the vector is disconnected from its direction, so no matter what direction it faces, its length will stay the same. The magnitude/length of a vector is always measured as its distance from [0,0,0].

I this case, if we normalize [5,0,0], it becomes a unit vector of [1,0,0]. This is now a direction vector, with a magnitude of 1. Notice how we can change the magnitude of the vector without changing its direction? We take advantage of this to get a random point on your line.

We can now take this unit vector and multiply it by any number we choose – let’s say 15.87. Now your vector becomes [15.87,0,0]. It retains its direction, but is now much further from the origin [0,0,0].

In your game, you’re going to be working with positions which are not at the origin. These are points in world space and you’re going to be working relative to them. To work with vectors, you need to convert these world space coordinates into local space coordinates – this just means you’re translating the origin to [0,0,0] so that you can use vector math.

Example: You have point A at [1,2,3] and point B at [6,7,8]. If you connect A to B, you get the line segment AB. This line segment has direction and magnitude, so it can be used as a vector. To get the line vector, you would subtract point B from point A: [6-1,7-2,8-3] => [5,5,5] [5,5,5] has the same direction and magnitude as line AB, but now its in local space because we shifted Point A such that it is centered on [0,0,0], and point B is on [5,5,5]. Now we can do vector operations on it! When we’re done, we shift it back by adding point A back into it."