Get a new location (x,y,z), from a starting location and angle. (vector math?)

I am trying to build a blueprint that makes a repeating wall.

The inputs for the blueprint include the Blueprint Class for the wall segment (a Packed Level Actor), the number of desired segments, and the length of each segment (I will try to auto-calculate the length from the segment later, but for now using a variable is easier).

The idea is that if I give it a wall that is 500 cm long, and say I want 5 segments, and have this blueprint located at 0,0,0 with a rotation of 0,0,0, then it should create these 5 walls:

Wall 1: loc: 0,0,0 - rot: 0,0,0
Wall 2: 500,0,0 - 0,0,0
Wall 3: 1000,0,0 - 0,0,0
Wall 4: 1500,0,0 - 0,0,0
Wall 5: 2000,0,0 - 0,0,0

I have a For loop tracking which wall segment to place. I use Get Actor Location to get the blueprint starting point. And I use Get Actor Rotation to get blueprint rotation.

My question is… how do I efficiently calculate the coordinates of the next wall segment? I’m sure I can brute force it by calling trig functions for all 3 dimensions, but I’m also certain that there MUST be an efficient vector math function that can do this, that is much more CPU efficient, and also results in a cleaner blueprint.

Okay, I think I have MOSTLY figured it out. I am posting the solution here in case it helps someone else.

This blueprint lets you specify a blueprint for a wall, a blueprint for a pillar, and then lets you choose how many times you want to repeat it.

It correctly uses all of the standard transforms, including position of the blueprint, rotation angles, and scaling. Here is an example of it in use:

When creating the blueprint, there are three things to watch out for on the Add Child Actor Component nodes (there are two, one for the wall and one for the pillar). Make sure Manual Attachment is set to True in the node, and in the Details set Mobility to Static, and Child Actor Component to None (it will be set by the blueprint anyway).

There is still one final thing I need help with, if anyone knows the answer to this: is there a way to dynamically get the width of the wall? The “Wall” variable is a Packed Level Actor class reference, and comprises of a variety of static meshes in a blueprint class. Surely there must be a way to determine this within the blueprint, instead of having to manually type it in.

It will not matter or it will be negligible in the grand scheme of things.

cleaner blueprint

This matters more, tbh.


In UE5, these are automatic:

In UE4 there a bunch of math nodes that each do their own thing. Vector * Int is a node afaik, so is scaling a rotator. Have a look at the Math section in the palette:


There’s also the Math Expression node:

image

Punch in the equation and click it to see what’s inside, the inside is usually like this, though:

Skinny Homer Homer Back Fat GIF - Skinny Homer Homer Back Fat Homer Simpson - Discover & Share GIFs

@pezzott1


I guess I posted it too late. OP is fast and their BP looks pretty good.

1 Like

Yeah, my blueprint is definitely looking like Homer’s backside right now, haha.

I might be able to further optimize it, and it could possibly use less nodes and lines, but then it would also become less readable. I think I might be afraid to touch it at this point, as well. :-p

Just need to dynamically get the length of the wall now, to replace the manual variable, and then I think this one will be a wrap.

You can get bounds of a static mesh comp:

image

The asset itself? Try:

Don’t ever, ever look inside.


Some notes in hopes to elaborate a bit:

  • You want to avoid repeating logic because it will double the work if you ever need to edit.
  • Child components are created in local space relative to the actor they are added to, that means all transforms are inherited so you can do the math in local space and avoid trasnforming world to local (something the set world node does behind the scenes).
  • You can use the bounds of each static mesh component to place them edge to edge seamlesly (if they are built to work that way) without the need to manually assigning a width.

As an idea this was done using what @Everynone posted above:

Like this you can scale the static mesh actor component to distort the bounds when placing them in a line.

Spaghetti

Edit: added the map find select to prove it updates the location per static mesh:

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.