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 speed inputs of the projectile movement be a start?

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

Thanks.

EDIT: made the picture clearer…

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

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.

!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

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.

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.

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

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:

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.

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.

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. :slight_smile:

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. :slight_smile:

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

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.

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

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

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.

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

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.

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 :slight_smile:

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.

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

Link

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.

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…

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.