Why is my projectile not shooting straight near my character?
I have got a little crosshair on my screen and want the projectile to be shot at where-ever the crosshair is pointing. If the max speed is set high enough, it'll go where-ever the crosshair is pointing at. But, when I aim at somewhere close to my character, it will shoot to the right of it.
Check last comment for Blueprint with answer
From the comments in the thread and your blueprint, it looks like you are doing this:
Getting the spawn location for the projectile by adding the
Depending on your
In order to achieve what you are looking for you have to compensate the projectile rotation to account for the difference in position from your projectile spawn point and the camera position. What I've seen people do is use a Line Trace from the
1) Get the position of a collision within a certain range (weapon range) and use that position to correct the projectiles initial velocity vector.
2) Get the position of some default max distance for the weapon in the direction of the camera look vector (your crosshair) and use the same logic as number 1 to get that point and correct the projectile initial velocity vector.
Hopefully this helps you get going with it! =)
Within the ProjectileMovementComponent settings, set gravity scale to 0. That will make sure your projectiles move in a straight line and is not affected by gravity.
To shoot exactly at the cross hair, however is a little bit more involved. The trick is to find a vector towards the world position of the cross-hair and set this as the rotation for your projectile. You can use Converted Screen space to world space node to get the world position of the cross-hair.
You cannot have exactly what you want with the constraints that are currently expressed.
You have the choice of either making the projectiles look like they come out of the gun, which will cause an offset from the camera-screen-center as long as the gun is off center, or making the projectiles follow the camera-screen-center, which will make the projectiles not look like they come from the gun.
You can change the animation to put the gun in the center of the screen -- straight in front of the camera. If you do this, the projectiles will follow the crosshairs. Or you can spawn the projectiles based on the camera ray, rather than the gun offset. This will send the projectiles in the direction you want, but will perhaps not look good.
answered Aug 24 '14 at 05:48 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here