Spawn based on player location and using player rotation

So, this is causing me few headaches, so I thought I’d ask on here…
I’m trying to work out how to spawn an actor at a random location within a defined ‘area’ that is based on the player location (which I can do), but that also takes into account the player rotation (which I can’t do!).
The idea being that then I could always spawn something behind, in front of or off to one side of the player.

I can do this without taking into account the player’ location - just the location, break the vector, apply some offsets and then remake the vector.
This gives this:

24014-spawn01.png

The problem is I can’t work out how to get this:

24015-spawnrot.png

Can anyone offer any suggestions?

Thanks

First of all look at this picture to know what I mean about GetActorForwardVector and GetActorRightVector.

As an example, I am going to write the pseudo code for generating a random location behind the player (the orange area).

Vector3 GetRandomLocBehindActor(AActor* P , float AreaW , float AreaH)
{
   Vector3 localX = P->GetActorRightVector()*RandBetween(-AreaW/2 , AreaW/2);
   Vector3 localY = P->GetActorForwardVector()*RandBetween(-AreaH , 0);
  
   return localX+localY+P->Location;
}

Look at these links too [GetActorRightVector()][2] , [GetActorForwardVector()][3] , [GetActorUpVector()][4]

feel free to comment if you find this answer too short and need more explanation.

Hi Sachamora,
Thanks for the advice - I think that all makes sense! Don’t know why I didn’t think of doing it like that…!
I’ll give it a go and let you know how I get on…

Cheers!

Hey!
So, it turns out, I didn’t understand your reply as well as I thought once I tried to implement it!
If I just use the vector based on the GetForwardVector things spawn in a nice line directly behind the player and taking into account for the player rotation. If I use the GetRightVector they do the same, but obviously in a line to the left/right of the player.
However, the problem comes when I try and combine these 2 vectors… If I do vectorF + vectorR (or localX + localY in your pseudo code) then it doesn’t work - have I got something wrong?

I’m doing this in a BP - so here’s a screenshot of my setup

Any further advice would be greatly appreciated!
Thanks

Hi, My mistake, I will update the pseudo code in answer, here is what you must change in your BP:

That’s got it!
Thanks for the help - much appreciated.