Move actor relative to camera rotation?

I have an actor which gets attached to a scene component on the first person player character.

The attached actor can be moved around using the WASD keys (separate from the first person character, pic at bottom). I would like for this attached actor to always move in relation to the camera, i.e. if it is rotated 90 degrees or 180 degrees no matter, W key will always make it move away from the camera, and A will always move to left side of camera.

Is there a way to accomplish this without a big chain of vector math? Just want to make sure there isn’t a simpler way before I twist my brain in a knot.

Example:
The compass and map are attached and follow the first person character around the world, taking on the characters rotation. If I add local offset to the compass, W will always move it along it’s local X axis. If I add world offset, it will not be aligned with the camera.

Take the compass. Is it a standalone BP?

Do you mean you’re attaching it to a scene component inside the player?

It’s working then. Cool :slight_smile:

It’s not too bad I don’t think. For sure moving backwards and forwards in front of the camera will be accomplished by just taking the forward vector from the camera, so depending on W and S, it will always be some multiple of

For the rotation, I assume you want to rotate the object around it’s own pivot point?

I’ll give this a shot today.

Rotation is already taken care of, it only rotates clockwise or counterclockwise on the Z axis so that never changes.

Trying both of these approaches, for some reason it is snapping the actor above the camera.

I tried isolating only the X and Y parts of the vector but made no difference.

Maybe something to do with that I am attaching these actors to scene components on begin play. Maybe that attachment is getting overridden or something?

alt text

Sorry, trouble getting these screenshots to work right.
Screenshot above shows result after using this code:

I also tried with the cameras world position, and both using the AddOffset and SetLocation nodes. They all give the same result.

The actors 0,0,0 location is right beneath the camera. There should be no movement on the Z axis, only sliding along the X and Y plane.

I tried isolating the vector multiplications to only be on X and Y but it is still always moving up on the Z axis.

Yes that’s correct.

And disregard my last response, I did correct issue with movement along the Z axis.

Now I have expected movement, it’s just going wrong way. But that’s simple to solve. I will confirm then mark your answer correct once I make sure everything is in order. It looks like the only change to your code that was needed was to split the struct and only use the X and Y locations (in my case only).

If it’s not that, then probably

I’m happy to report there actually was an easy way to do this without vector math involved (or at least, Epic has already done the math for us.)

The AddRelativeLocation node does the trick, the key is it has to be used on the static mesh component, not the entire actor. To be honest I am not 100% sure what the difference is since the StaticMesh here is the root component of the actor, but in any case, it works.

Thanks for the help, it wasn’t in vain as I did learn a bit more about vector maths which will come in handy in the future I’m sure.

342464-screenshot-2021-06-26-075652.jpg