spawning actor behind player position
I started to learn Blueprint system and find it really great. What i am trying to do now is to place a class (actor) behind player "movement" or at his back. I've already created BluePrint class with sphere object and i can trigger event when "space" is being pressed. Also i got vector of movement of the player , though i have 2 problems i am not sure how to resolve. First i need to place object "behind" player , at his back when he is moving. So i assume this should be like this :
determine vector of movement (x as example)
spawn position = position of player (x - 5 , y , z)
This is simple algorithm though i am not sure how to interpreter it in Blueprint language. The second thing is to detect last vector of movement (when player just stands still) , and class is spawned behind him.
Create a blueprint for the class that you want to spawn, or use an existing one,
and then use the Spawn blueprint node!
if you cant find it, turn context sensitive off
Get Forward Vector
Get the player character unit
Get the player's Forward Vector
Multiply by a NEGATIVE number
that will be behind the facing direction of the player character
Nor as simple as you think :)
This is a very hairy question because one can't just compute what Rama proposed (`spawnPosition = -ForwardVector offset`). That would end up with spawning in a wall, into a prop and so on... any actor relative automatic spawning system must be environment-aware*, and that is not an easy task.
The easiest way to do so is to sphere-cast on the computed spawnPosition from above to determine the ground level at that given point. Here you alse have to make sure that you indeed hit the ground and not something else, so you can use layering or tagging to define and isolate where you can actually spawn your pawn on.
Once you have a clear surface you also need to make sure to have enough space, so I would spawn a collision volume having the very same bounds of the pawn you want to spawn. This has to be there for just 1 frame to detect any overlap and tell you back that an overlap occurred, so that you can look for another spot where to spawn the actor.
answered Mar 26 '14 at 12:16 AM
Pino of DFT Games
Follow this question
Once you sign in you will be able to subscribe for any updates here