DSprtn / GTFO_VR_Plugin

A plugin to add full roomscale Virtual Reality support to your favorite game!
MIT License
143 stars 13 forks source link

Fix shotguns not firing in weapon direction #56

Closed Nordskog closed 9 months ago

Nordskog commented 9 months ago

The problem

Starting with ALT://R6, all shotgun-type weapons will fire in the direction the player camera is facing, rather than in the direction the muzzle of the weapon is pointing.

broken_shotgun.webm

This only affects shotgun-type weapons.

In the InjectFireFromWeaponMuzzle patch, BulletWeapon.Fire() is hooked and the player FPSCamera position and direction is changed to that of the weapon's MuzzleAlign. At the time of implementation, weapons would fire forwards from the center of the camera. In more recent versions of the game, shotgun-type weapons have been subclassed into Shotgun, with its own Shotgun.Fire() implementation, meaning the above patch does not affect it.

The reason this never broke anything is because, up until ALT://R5, they had both been changed to use the position and orientation of the weapon MuzzleAlign, rather than the camera transform, making the above patch redundant.

With Alt://R6, Shotgun.Fire() in particular was heavily modified, and now uses the orientation of the camera again, but not directly.

The fix

fixed_shotgun.webm

The player FPSCamera itself does not have a local transform. It is nested under a FPSCameraHolder and a FPSCameraRotation object, which handle translation and rotation respectively.

Shotgun.Fire() uses the FPSCameraRotation transform to determine where the weapon should fire, so we simply need to change its position and rotation for the duration of the call, and then revert them, similar to what InjectFireFromWeaponMuzzle does.

There does not appear to be any direct references to the FPSCameraRotation GameObject, but it is the direct parent of FPSCamera, making it easily obtainable.

DSprtn commented 9 months ago

Nicu!