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):
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
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.
answered Feb 11 '16 at 08:06 AM
Follow this question
Once you sign in you will be able to subscribe for any updates here