How to use transform to spawn actor relative to other actor?
I want to spawn an actor with a position and rotation relative to another actor, and I'm not really sure how to do it properly.
For example say I have actor1 which is a face, and actor2 which is a wooden plank. I want to spawn that wooden plank right in front of the face.
If actor1 was at location (0,0,0) with rotation (0,0,0), I know that I have to spawn my actor2 at (50,0,0) with rotation (0,0,0), to have it appear in front of the face.
Unfortunately the actor1 is no longer at this start location, nor rotation, so how can I spawn actor2 at the right position and rotation? I tried using their transforms, multiplying the actor1 transform with the relative transform (with the translation of (50,0,0) of actor2 but that didn't quite work right...
Anyone can help me out here?
asked Apr 29 '16 at 11:10 PM in C++ Programming
I know I'm late, but anyways!
While spawning an actor, the Transform you specify for its location is at World Space. Your actors need to be attached, in order for the location to be relative. A simple AttachTo should suffice.
On the other hand, if you do NOT want to link the actors in any manner (as should be in this case) you need the actor's World Transform, probably taking it from the root component. Add, then, the location offset and rotate it accordingly (you'll need the "Front" vector of your main actor and rotate that in Z). Then, use that transform to spawn the plank.
answered Oct 03 '16 at 03:16 PM
† SG †
To get coordinates that are -175 units from the location of the actor in relative space:
Then you could just feed this value in to the Spawn Actor node.
answered Sep 20 '18 at 09:41 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here