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"

FPS Projectile Doesn't Spawn In Right Location When Not Facing Forwards

Good Day,

I am having issues with creating an FPS blueprint using projectiles.

When I fire the weapon facing either forwards or backwords the projectile spawns at the proper location and faces the target location I have set. alt text

Yet When I face either left or right, the bullet will spawn on the left or right side of the weapon.

alt text alt text

The projectile should be following the blue raycast line as this line starts at the proper projectile start point and ends at the impact point of another raycast that was cast from the centre of the screen, red being the impact point.

Here is the blueprint I have on the projectile. Ignore the first sequence as this is entirely unrelated to movement in anyway. After this I set the projectile's speed with an exposed variable "Projectile Speed". Next I change the direction the projectile is facing to the point in the world that the Red raycast hit. The projectile should move in a straight line so if it looks in the right direction it should hit the proper point. The Target variable is another variable that I expose on spawn and set in the shooting blueprint. The last thing I do is draw the debug line that the projectile is supposed to be following.

alt text

Next is the blueprint I use for shooting and setting up the variables/spawn point of the projectile. So after telling the game that we are shooting/holding down fire I cast a raycast from the centre of the screen and find where this line hits the world. Next I spawn the bullet at a set location just in front of the barrel of the gun. This is where "Sphere" is located. So I take this world location, and add the world rotation of the first person camera to spawn it in the right location, and facing the right direction. I then set target (which is used in the previous blueprint) to the hit location of the raycast.

alt text

I have tried ignoring the rotation and just using the GetWorldRotation of Sphere which lead to the same result. I tried using GetForwardVector of "First Person Camera", converting that into a rotation and plugging that into the RotateVector and that also didn't change anything. At this point I feel a little lost and unsure what else I can check or change to make this work.

Thanks for looking at this and helping a beginner out!

Product Version: UE 4.16
forward-view.png (288.2 kB)
left-view.png (238.6 kB)
right-view.png (222.8 kB)
shooting.png (448.1 kB)
more ▼

asked Oct 17 '17 at 04:19 PM in Blueprint Scripting

avatar image

8 1 2 4

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

1 answer: sort voted first

I am confused by your rotating around 0,0,0. I think this does nothing. I think rotating a 0,0,0 vector should produce 0,0,0. But it could return a unit vector instead. (See below).

In any case, you should be using Sphere's GetWorldTransform instead of creating a transform out of Maths. Start with that.

If that doesn't fix it, post an image of how your sphere is attached to the gun.

Pulling an answer out of nothing, based on the behavior of your spawn point, it looks like you're adding a constant vector to it's location. Something like 1,0,0, so your spawn point is always shifted 1 unit to the north. If this is true, your south/backward image would show the block slightly closer to the barrel. Try looking for something like that.

more ▼

answered Oct 17 '17 at 07:41 PM

avatar image

151 4 10 11

avatar image DayV_Jones Oct 17 '17 at 10:46 PM

So I set the spawn location to be just the Spheres world transform, and a couple things..

First thing is that the issue from before hand still persists. And I can now confirm that it is being moved north when it is spawned. Also another weird thing too is that now the projectile is really tiny. I had to make the blue raycast smaller just so you could see the projectile.

alt text

The red ball is where Sphere is located. Here's another image of just the fps controller in the viewport

alt text

And here is what the updated blueprint for shooting looks like

alt text

Thanks for the quick response, it is greatly appreciated.

avatar image Ecnassianer Oct 18 '17 at 12:21 AM

It's tiny because the sphere has been scaled down, and the sphere's transform contains that scaling. Why are you using a sphere? Ideally you'd use a marker/bone on the mesh, so that when the art changes, so does the projectile positioning. If you're just using placeholder meshes, and would rather just having a component for it, I would try using a Scene Component instead. That way you can leave the scale at 1.0,1.0,1.0 and use the transform directly. Though, I guess then you can't debug render it. Or just break the sphere transform, and make a new transform with the sphere's location and rotation and a 1.0,1.0,1.0 scale.

But back to your original problem. Everything in your blueprints look fine to me. I'd start looking for other places that the projectile might be getting offset. Is the box component at 0,0,0 local space inside the projectile? Is there anything in the projectile blueprint that's moving it? Are there any offsets in the projectile's details? Do any other blueprints reference/adjust the projectile?

If you can strip down your project to just the blueprints you need for this (maybe exporting your character to a new project?), and post a sample project, someone might be able to find the problem somewhere.

avatar image DayV_Jones Oct 18 '17 at 03:06 PM

I changed the Sphere to a scene component and that fixed everything. The positioning of the spawned projectile, the scale of it, everything.

My blueprint for the shooting looks identical to the previous picture except the sphere world transform is replaced with a scene object transform (located at the same location the sphere was)

Thanks again for all the help.

avatar image Ecnassianer Oct 18 '17 at 03:30 PM

Huh, I kinda surprised that fixed it. Glad you're working again though! :D

(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