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"

AnswerHub Maintenance

Background maintenance is scheduled to occur between 9 - 11am EDT on Tuesday, May 21. Site operation may be slower than normal during this time and a brief interruption in operation may be observed

Third Person Shooting, projectile directions + Bullet spread

Hi there, what I would like to do is have the projectile move towards the centre of the screen (where the crosshair is placed at) rather than just coming straight out of the characters chest and moving foward from there, is there a way that the projectile movement component can be changed or is there an option to allow for this, or would I have to use some other method of making the projectile move?

As an extension, would altering the direction the projectile flies along randomly each shot be possible?

Currently I just have the projectile fly out of the characters chest, but as you can see here, the projectile never actually meets the crosshair, and if the character is closer to the wall the projectile appears even farther from the crosshair.

EDIT: As you can see in the image, the blue 'X' is where the projectiles spawn, the red arrow path is how they travel, which is not broken, that's how the projectile is set up, to fly straight forward from where it's spawned based on that direction, but what I want is to alter that direction so that the projectile always flies towards and eventually intersects the crosshair. So essentially I'm asking how to modify the direction of the projectile, or what direction I should go in to do so.

Blueprint for reference, although it's nothing special or complicated.

Would using the velocity vector input rather than the initial and max speed inputs of the projectile movement be a start?

Any help or pointers in the right direction would be much appreciated.


EDIT: made the picture clearer..

Product Version: Not Selected
more ▼

asked Jul 05 '14 at 09:22 AM in Blueprint Scripting

avatar image

51 10 12 17

avatar image LPUnreal Jul 05 '14 at 03:04 PM

I don't fully understand what you are doing and what you want to do. Some further explanations of yours would be necessary here. :-)

When spawning the projectile you need to have a spawning position and direction. Where are you taking these from?

And another thing. Are you sure you want to have the projectile fly towards the center of the screen? In a third person game the camera is normally above and behind the character model. So a projectile flying towards the center of the screen would go up and backwards if spawned from the position of the weapon..

What I think you want to do is a line trace from your viewing direction to check if you are aiming at something and then fire a projectile towards the object you were aiming at.

avatar image Recker Jul 06 '14 at 05:21 AM

Alright, what I am doing is spawning the projectile like normal, it uses the the camera booms location which has been offset by a small amount, and it also uses the rotation, when it spawns the projectile movement kicks in and it flys straight. My problem is that it's not moving towards the crosshair, I would like to fire the projectile from the character and have it move towards the crosshair.

I don't really know how else to explain it.

(comments are locked)
10|2000 characters needed characters left

11 answers: sort voted first

I think both of you are mistaken. Also possible that I am but let me explain.

The cross hair interpreted as a point in 3D space has its position right on the camera screen (lens). In a third person game the camera is normally above the character (somewhere in the sky). So the camera screen and especially the cross hair is somewhere in the sky as well. So if you spawn a projectile at your weapons location and let it fly towards the cross hair it will be flying towards the sky. :-)

What you want to do is spawn a projectile at your weapons position and let it fly towards your target. The question is what is your target and that is what you have to find out.

In a third person game you use a line trace from your cameras origin through the cross hair (that's the viewing direction). Check if you were aiming at something and if so spawn a projectile from the weapons position towards the target. So your projectile takes a different line than your aiming direction, but they should intersect at the targets position. From the camera perspective the projectile and the cross hair overlap but aren't (!) at the same position. You could think of the cross hair as a rifle scope. Bullets don't fly towards the rifle scope. :-)

I never used Blueprints but here is a blueprint how you can do a line trace to find a target in BP. BP Aiming

more ▼

answered Jul 06 '14 at 03:37 PM

avatar image

46 4 4 7

(comments are locked)
10|2000 characters needed characters left

So here's what I did. I don't know the best practices, but this worked for me and I was stoked!

So I [ Get Player Controller > Convert Mouse Location to World Space > World Direction plugs into my rotate vector ] after this everything is plugged into the spawn projectile the same way the first person blueprint has it set up (make transform > spawn transform etc).

The blueprint is probably clearer than my explanation.

alt text

tps.jpg (187.1 kB)
more ▼

answered Aug 18 '14 at 04:22 PM

avatar image

56 4 7 26

avatar image lunix Aug 18 '14 at 07:46 PM

Looks like your get control rotation is where the magic happens as you are only using the screen to world node for the position. I shall try this new magic node when I get home :)

avatar image zlspradlin Aug 18 '14 at 07:53 PM

Let me know how it goes, I'm so new to UE4 that even if I get something to work I may not fully understand/comprehend it.

(comments are locked)
10|2000 characters needed characters left

Check my answer to this question for 1st person... it's essentially identical.


For bullet spread, you can simply get some random vector of a small size and apply it to the Trace Hit position. This would simulate that for you.

Edit: The "Shooter Game" example does the things you are looking for. Proper aiming with an offset muzzle location as well as bullet spread.

more ▼

answered Aug 18 '14 at 08:02 PM

avatar image

1.6k 61 45 237

(comments are locked)
10|2000 characters needed characters left

!This not a complete answer!

What you can do here is to make the projectile fire straight at the cross hair. To do that you need to convert the screen coordinates into world position. At the moment I could not find the right blueprint node to do that. I heard that such a node might be available in 4.3 release.

The following BP shows the general idea. But it uses the mouse cursor position instead of Crosshair (UE4 already has a node to de-project mouse cursor location). So it will fire staright at where you are positing with the mouse (you must enable Mouse cursor in PlayerController settings).

So I think you can use this to base your logic on. You still have to do some offsetting so that player does not overlap with projectiles when you are running forward while firing. Still at the moment it only fires at the cursor location. I will see anyone has found a way to de-porject an arbitrary location to world space

take a look at the ShooterGame code too. It does random changes to projectile direction to simulate gun-recoil and firing them straight at cross-hair

alt text

solbpssa.jpg (122.9 kB)
more ▼

answered Jul 05 '14 at 03:35 PM

avatar image

3.4k 154 51 271

avatar image Recker Jul 06 '14 at 05:34 AM

The shooter game doesn't really help because it seems a lot of the important stuff is code based rather than blueprints, if it is blueprints it's hidden really well because I couldn't find it.

The problem with your blueprint is it doesn't apply, what yours does is fire the projectile from the mouse position, whereas I want to fire it from the character to the crosshair position.

What I'm struggling with is finding a way of saying the direction of the projectile is the the direction of the crosshair in accordance to the spawn area.

As you can see in the screenshot, the blue x is where the projectiles essentially come from, the red arrow is where they travel which is fine because that's how it's currently set, but what I'm aiming for is to have the projectile hit the crosshair rather than off to the side of it.

avatar image mindfane Jul 06 '14 at 08:11 AM

I undersatdn your requirement. But the problem is we need a method to convert the position of corsshair into world coordinates. The blueprint I've shown is just a concept. As I have stated, it is not the solution, but more like a tip. Once we can convert any screen coordinate into world space, I think it will work for you. Essentially the 'Convert Cursor to World Space' will be replaced with 'Convert Screen Pos to World Space'

Here is a similar question. Look for the answer given by Steve Allison https://answers.unrealengine.com/questions/17143/convert-screenpoint-to-worldspace.html

At the moment this can be done in C++, but with blueprints, looks like we will have to wait for 4.3 release.

Is your cross-hair always at the center of the screen?

In that case, perhaps you could use this: alt text

center_fire.jpg (96.8 kB)
avatar image Recker Jul 06 '14 at 09:40 AM

Ahh I see now, sorry I misread slightly, it's a shame that it's only available in C++ currently, hopefully 4.3 is quick to be released then.

It's still in the air as to whether the crosshair will move or not, but presently it just sits dead centre of the game window.

I've tried some some extra things, like calling a trace and then getting the angle between the trace end and the camera world location, and using that angle as the rotation, which sorta worked, but if the trace didn't hit anything it would go funky.

Thank you for your help regardless.

avatar image mindfane Jul 06 '14 at 12:47 PM

I think I understand. IF your cross-hair is always at the middle of the screen, the above blueprint will make sure the projectiles go toward the cross hair (provided the projectile's Gravity multiplier is 0).

I will let you know if I find anything that might help you. Meanwhile try the forums too.

(comments are locked)
10|2000 characters needed characters left

I was having an issue with firing in third person. I think I've got it mostly figured out (I haven't done anything with the spread part though).


I was having the same problem where it seemed to always be off to the left a little bit. With the spread, it would probably be a random value between two small numbers (like -5 to 5) for x, y, and z values. Each having their own random float in range node so the random number is not the same for each axis.

more ▼

answered Jul 06 '14 at 10:07 PM

avatar image

25 3 4 9

(comments are locked)
10|2000 characters needed characters left

Set rotation to zero. It should solve your problem ;).

more ▼

answered Jul 06 '14 at 10:15 PM

avatar image

1.6k 102 97 181

(comments are locked)
10|2000 characters needed characters left

Has anyone figured out a good answer to this. I have the same exact dilemma

more ▼

answered Aug 18 '14 at 03:51 AM

avatar image

76 14 21 25

avatar image Recker Aug 18 '14 at 04:09 AM

I've sorta changed how I implemented it originally mainly because it was giving me a headache, as someone mentioned before you can now use a node called 'convert screen location to world space' and use that to set the end point of the 'find look at rotation' node along with some other trickery to get the projectile movement.

What I am doing now is just using a couple of traces to first get the distance to any vision blocking thing, which will set the distance for the actual shot trace to set itself to.

avatar image lunix Aug 18 '14 at 11:29 AM

any chance you could post the BP of this? I'm still having troubles #nosleep

avatar image VedgyB Aug 20 '14 at 07:23 AM

I'd really appreciate seeing a BP of this as well... I sort of understand the logic behind how it works but don't know how I'd start to implement it.

avatar image Recker Aug 20 '14 at 07:20 AM

I actually just discovered a bit of an issue with the bullet spread after some testing so I'm going to remake it (yet again), if I get it working I might post here for you...

(comments are locked)
10|2000 characters needed characters left

Tesla Dev has a tutorial on this. Do a google search for Simple Line Trace Tesla Dev.

The crosshairs that is displayed with the FPS template is not quite in the center of the screen so it will look a little off when shooting.

more ▼

answered Feb 18 '16 at 02:38 AM

avatar image

25 3 4 9

avatar image Recker Feb 18 '16 at 03:14 AM

I have long since figured this out and have moved on due to losing the project and forgetting about this post...as such, Tesla's video doesn't exactly help, he was using a line trace whereas I was originally using a blueprint actor with a projectile movement component...

With a trace things will have to work a little different, but even then there are a couple of variations, there could be a bullet blueprint that casts the trace by itself, or the trace casting could be based straight in the character actor... Tesla while great keeps things simple, and bullets can get very complex if need be.

(comments are locked)
10|2000 characters needed characters left

Hey Recker I saw your video on YouTube and shooting towards crosshair is now working! I have tried almost all answers on internet but none of them is working for my projectile and I feel weird... I really need help on this. This is what I have but it is still off. I am having my shooting logic in Character BP class. I have a muzzle location on top of my character and outside of my capsule component.

shoot1.png (184.0 kB)
shoot2.png (166.5 kB)
shootscreen.png (852.3 kB)
more ▼

answered Feb 18 '16 at 02:09 AM

avatar image

31 1 2 2

avatar image cyborgjynx Feb 18 '16 at 02:41 AM

Tesla Dev has a tutorial about this. Search for Simple Line Trace Tesla Dev.

Also note that the crosshairs that's on the screen for the first person template is not quite in the center of the screen. It's very close but not quite.

avatar image MaxISoP Feb 18 '16 at 02:47 AM

No it doesn't work for me I tried. I am using my camera to adjust my projectile arc in future (like projectile in GoW). And based on my BP I can't see what is going wrong, but the projectile is not flying to crosshair.

avatar image Recker Feb 18 '16 at 03:06 AM

Hey there, sorry I have long since lost the original files for those projects including the stuff I put on my youtube... I think what I did was cast a trace from the camera straight forward using the cameras rotation, while also getting the forward vector and setting the length to about 200 meters, and then I store the hit location if the trace, after which I spawn the projectile blueprint OR cast the actual projectile trace from the character...Directly after that spawn I grabbed the spawned actor and set its rotation with a find look at rotation node, using the spawn location and the hit location.... what you can then do after is add some variation to that by breaking the rotation before its set, and adding a random node on each of the rotation axis, that will simulate spread... you could also do another thing where if the trace doesnt hit anything you could set a bool variable or something you just set the target of the find look at rotation node to a large number like 200 meters from the players position.

avatar image MaxISoP Feb 18 '16 at 03:10 AM

Thank you for the explanation! cyborgjynx has helped me out. I am pretty sure I get my projectile flying to crosshair correct now, but like he explained, the crosshair itself is a little bit off since I am now using the crosshair from FPS template. Gonna fix that now. Thanks again!

avatar image CamWitWizard Aug 13 '18 at 07:07 AM

This sounds like another question on the forums so if anyone wants the blueprints, I found some here: https://answers.unrealengine.com/questions/404300/make-player-shoot-a-projectile-that-collides-with.html Although, I haven't manged to get them to work in my 3P project, that's probably just cause I'm an newbie

(comments are locked)
10|2000 characters needed characters left

In the line trace start use the cameras location and not the muzzle location.

more ▼

answered Feb 18 '16 at 02:52 AM

avatar image

25 3 4 9

avatar image MaxISoP Feb 18 '16 at 02:57 AM

It works now! I am using the same crosshair implementation as FPS template so it is a little bit off but it is a constant of no matter how I change my camera location or rotation. Can you explain why this does the trick please? And can you point me a place to find a good crosshair implementation? Thanks you so much!!!

avatar image Recker Feb 18 '16 at 03:18 AM

With the crosshair, you can go to the hud blueprint and subtract I think it was a value of 8 from the x and y of the crosshair location image... as far as I know the image origin is based on the top left of the crosshair and IIRC its only 16x16 pixels...

also I personally wouldn't use the camera location as the start point for the trace as if there is something in between the camera and the player location even briefly while shooting it can cause issues with projectiles...

avatar image MaxISoP Feb 18 '16 at 03:35 AM

I see... but using camera location as start position for line trace solved the problem for now... Or I think I can create an empty mesh on top of my character's head and aligned with camera location. What did you use for that start point?

avatar image Recker Feb 18 '16 at 03:38 AM

Check out my comment to your other post, I made a short breakdown...

(comments are locked)
10|2000 characters needed characters left

This guy has an amazing explanation that I barely understood but it seemed to solve your problem (If you haven't already solved it 4 years later) But this is manly for anyone who finds this post and needs a good explanation: https://answers.unrealengine.com/questions/404300/make-player-shoot-a-projectile-that-collides-with.html Credit to Taydra for solving the problem btw

more ▼

answered Aug 13 '18 at 07:11 AM

avatar image

1 1 2

(comments are locked)
10|2000 characters needed characters left
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