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"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

spawn on mouse location

Hi ,I want to spawn an specific actor on mouse cursor location , so far this is my code (on character class):

 UWorld* const World = GetWorld();
 if (World) {
     FActorSpawnParameters SpawnParams;
     SpawnParams.Owner = this;
     SpawnParams.Instigator = Instigator;
     FRotator SpawnRotation = FRotator(0,0,0);    
     APlayerController* pc = World->GetFirstPlayerController();
     FVector Direction = FVector(0, 0, 0);
     FVector Location = FVector(0,0,0);
     pc->DeprojectMousePositionToWorld(Location, Direction);
     FVector SpawnLocation = FVector(Location.X,Location.Y, 0);
 
     APickup2* YC = World->SpawnActor<APickup2>(BlueprintVar, SpawnLocation, SpawnRotation, SpawnParams);    
 }

but what dose this do is spawning my actor on player location, not exact location of cursor.

i want something like this but with c++ : https://www.youtube.com/watch?v=koHL5UQlSo4

Product Version: UE 4.10
Tags:
more ▼

asked Feb 10 '16 at 07:16 PM in C++ Programming

avatar image

sajedn
3 1 2 5

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

1 answer: sort voted first

There's nothing like mouse location in game's world in this case. Your mouse location on screen translates to a ray in the game's world (i.e. all the points below the cursor), so you first have to decide at which point of the ray you want to spawn the new object.

To uniquely define a ray you need a starting point and a direction of the ray. You already have them from DeprojectMousePositionToWorld named Location and Direction. However, what you're doing now is spawning the object at Location(ish) which is where the ray starts -> i.e. spawning on your player's location.

What you really want to do I think is to spawn in the place where the "mouse ray" intersects another actor. Try to do a raycast into the world like here: https://answers.unrealengine.com/questions/125430/how-to-ray-cast.html

You'll find an intersection position and then use that position as the spawn location.

more ▼

answered Feb 11 '16 at 08:06 AM

avatar image

fszczemton
291 16 19 248

avatar image sajedn Feb 11 '16 at 04:05 PM

ty, this is exactly what i needed.

(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