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.
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
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?
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).
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.