FPS Projectile Doesn't Spawn In Right Location When Not Facing Forwards
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!
asked Oct 17 '17 at 04:19 PM in Blueprint Scripting
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.
Follow this question
Once you sign in you will be able to subscribe for any updates here