[SOLVED] RailAttack Offset Reconfiguring

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom Developers

Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
User avatar
Exosphere
Posts: 166
Joined: Sun Jun 11, 2017 11:42 am
Location: New England, US

[SOLVED] RailAttack Offset Reconfiguring

Post by Exosphere »

I've noticed that the where the beam actually hits when using A_RailAttack is significantly lower than where a person is actually aiming, directly under the crosshair by a lot. I know that A_FireBullets behave the same way, but the distance from where the bullets actually hit and the crosshair is negligible. How can I change the height/position/whatever-its-called of where the beam will actually hit, without modifying player height?

How A_RailAttack Currently Works
railattack1.png
How I want A_RailAttack To Work
railattack2.png
You do not have the required permissions to view the files attached to this post.
Last edited by Exosphere on Mon Nov 14, 2022 8:48 am, edited 1 time in total.
Jarewill
Posts: 1400
Joined: Sun Jul 21, 2019 8:54 am

Re: RailAttack Offset Reconfiguring

Post by Jarewill »

That's actually the default behavior for all player attack, hitscan or projectile.
However the attacks aren't aimed below the crosshair, they are simply fired from a position below the crosshair but still go at a straight line according to the player's angle and pitch.
There's actually a mod that fixes the default crosshair to be correct.

Now for fixing this there are two ways.
If you want it to apply to only your railgun, you have to edit one of the many parameters of A_RailAttack, namely spawnofs_z.
By default attacks start at 36 units and the camera view is set to 41 units, meaning you have to set the spawn offset to be 5.

And if you want it to apply to all weapons, change the Player.AttackZOffset variable inside your player class to be the same as the ViewHeight, which is 41 by default.
Note that AttackZOffset is actually an offset from the middle of the player's hitbox unlike ViewHeight, so to match them you have to divide the Height (default: 56) by half and then add enough offset to end in 41, which should be 13 with default Height and ViewHeight.

I should note that the projectile spawn location is lower than the default camera for a reason, as if it's set to be the same projectile attacks will tend to block the camera.
User avatar
Enjay
 
 
Posts: 26430
Joined: Tue Jul 15, 2003 4:58 pm
Location: Scotland

Re: RailAttack Offset Reconfiguring

Post by Enjay »

Jarewill wrote: Sun Nov 13, 2022 11:55 am However the attacks aren't aimed below the crosshair, they are simply fired from a position below the crosshair but still go at a straight line according to the player's angle and pitch.
Indeed. Or using OPs graphic format, something like this:
Image
User avatar
Exosphere
Posts: 166
Joined: Sun Jun 11, 2017 11:42 am
Location: New England, US

Re: RailAttack Offset Reconfiguring

Post by Exosphere »

Jarewill wrote: If you want it to apply to only your railgun, you have to edit one of the many parameters of A_RailAttack, namely spawnofs_z.
By default attacks start at 36 units and the camera view is set to 41 units, meaning you have to set the spawn offset to be 5.
Awesome, That did the trick! Thank you! Its good to know for the future. I’ll probably use this in a case-by-case basis.
Enjay wrote: Indeed. Or using OPs graphic format, something like this:
Very interesting. I didn’t think of it being like that. Why is A_RailAttack positioned like this in the first place? Is it because the particles from RailAttack would obstruct the player camera?
Jarewill
Posts: 1400
Joined: Sun Jul 21, 2019 8:54 am

Re: RailAttack Offset Reconfiguring

Post by Jarewill »

Exosphere wrote: Sun Nov 13, 2022 8:03 pm Why is A_RailAttack positioned like this in the first place? Is it because the particles from RailAttack would obstruct the player camera?
As I mentioned before, this is the case for all player attacks and not just the railgun.
I also think it's because projectiles would obstruct the player camera (as railgun attacks weren't in Doom originally) and autoaim solved all aiming problems, so there was no need to code in special logic for hitscan attacks.
User avatar
Enjay
 
 
Posts: 26430
Joined: Tue Jul 15, 2003 4:58 pm
Location: Scotland

Re: RailAttack Offset Reconfiguring

Post by Enjay »

Exosphere wrote: Sun Nov 13, 2022 8:03 pm Very interesting. I didn’t think of it being like that. Why is A_RailAttack positioned like this in the first place? Is it because the particles from RailAttack would obstruct the player camera?
That may well be part of it. However, all attacks are like this by default. The player view height and attack z offset can be modified in a custom player class (or individual weapons can be modified) and you can figure out values that mean the crosshair and attack hit location are at the same position but, by the original game defaults, they aren't.

In fact, the original values are pretty weird. Even the player view height puts Doomguy's eyes somewhere in his chest rather than his head.

Return to “Scripting”