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.
Yet When I face either left or right, the bullet will spawn on the left or right side of the weapon.
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.
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.
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!
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.
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.
The red ball is where Sphere is located.
Here’s another image of just the fps controller in the viewport
And here is what the updated blueprint for shooting looks like
Thanks for the quick response, it is greatly appreciated.
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.
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.
Huh, I kinda surprised that fixed it. Glad you’re working again though!