x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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:

alt text

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

alt text

Can anyone offer any suggestions?

Thanks

Product Version: Not Selected
Tags:
spawn01.png (5.9 kB)
spawnrot.png (12.5 kB)
more ▼

asked Dec 14 '14 at 06:03 PM in Using UE4

avatar image

teed
38 9 11 14

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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

alt text

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() , GetActorForwardVector() , GetActorUpVector()

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

help.jpg (51.8 kB)
more ▼

answered Dec 14 '14 at 08:32 PM

avatar image

Sachamora
152 14 16 22

avatar image teed Dec 15 '14 at 04:18 PM

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!

avatar image teed Dec 15 '14 at 08:19 PM

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

alt text

Any further advice would be greatly appreciated! Thanks

sshot-5.png (182.7 kB)
avatar image Sachamora Dec 15 '14 at 09:35 PM

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

alt text

24151-sshot-5.jpg (250.7 kB)
avatar image teed Dec 15 '14 at 11:59 PM

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

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question