Hello friends.
There is a small bug on my game, I think it’s the most significant bug, and I think it can break the gameplay especially on closed maps.
For the sake of getting a bit more of realism, I decided to make all my game’s guns as projectile guns instead of Instant Hit. Because this way I can set some specific physical properties for the bullets for each weapon (speed, acceleration, damage, and so on).
And added to this, I made a particle effect to simulate the bullets tracing, which made it look very nice.
However, I have a bug, that initially I thought no one would realize it, but now, after too many downloads of my game’s demo (1200 downloads), many players complained about this.
The bug in question is that, whenever the player pawn is** leaning back against the wall **(any static mesh), the projectile is not ejected from the gun, or better, it hits the wall behind him on the height of the player camera, this way:
The function is
simulated function vector GetPhysicalFireStartLoc(optional vector AimDir) from UTWeapon.uc class.
This is the line of code which controls the projectile fire action:
FireStartLoc = Instigator.GetPawnViewLocation() + (FireDir * FireOffset.X);
I suspect it has to do with the player camera, because, as I am using **BehindView **camera to make a 3rd person view, and on the moment the player leans his back against the wall, the camera changes it’s point of view, and the fire start location is calculated based on the Pawn View Location.
After digging the code UTWeapon.uc, and a lot of trials and errors, I changed the Fire Start Location to this:
FireStartLoc = Instigator.Location - FireDir*FiredProjectileClass.default.CylinderComponent.Translation.X;
FireStartLoc.Z = FireStartLoc.Z + FMin(Instigator.EyeHeight, Instigator.CylinderComponent.CollisionHeight - FiredProjectileClass.default.CylinderComponent.CollisionHeight - 1.0);
This seemed to solve the problem, now the projectile is fired from the gun, no matter the player position, even if he is leaning against a wall.
However, a side effect now is that, as it does not take into consideration the fireoffset anymore,** I lost accuracy on the aim**, which means the projectile never hits the center of the crosshair. It sometimes hits, especially when the player is far from to the target, but whenever I zoom the aim (right mouse button), or the closest the player moves towards the target, the projectile moves away from the crosshair towards the left direction.
The old calculation ( FireStartLoc = Instigator.GetPawnViewLocation() + (FireDir * FireOffset.X); ) gives perfect accuracy to the aim, as the projectiles hit the exact center of the crosshair, no matter the player position or camera angle (except the bug whenever leaning the back against a wall).
Any help?