Changing mouse speed in ZScript
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!)
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!)
- Jekyll Grim Payne
-
- Posts: 1069
- Joined: Mon Jul 21, 2008 4:08 am
- Preferred Pronouns: He/Him
- Graphics Processor: nVidia (Modern GZDoom)
- Contact:
Changing mouse speed in ZScript
Is there a way to scale or change mouse speed temporarily? I need to create a melee weapon attack that limits the player's ability to turn around while it's performed but doesn't disable it completely.
Re: Changing mouse speed in ZScript
I wonder if investigating how [wiki]A_ZoomFactor[/wiki] does its thing? By default, it scales mouse sensitivity to reduce mouse movement speed when zoomed in.
- Jekyll Grim Payne
-
- Posts: 1069
- Joined: Mon Jul 21, 2008 4:08 am
- Preferred Pronouns: He/Him
- Graphics Processor: nVidia (Modern GZDoom)
- Contact:
Re: Changing mouse speed in ZScript
I'm not sure any scaling is actually involved, but I couldn't find definition of A_ZoomFactor inside gzdoom.pk3 (and exporting Zscript folder from it won't help because, sadly, my OS is for some reason incapable of searching file contents...)
- ramon.dexter
- Posts: 1529
- Joined: Tue Oct 20, 2015 12:50 pm
- Graphics Processor: nVidia with Vulkan support
- Location: Kozolupy, Bohemia
Re: Changing mouse speed in ZScript
You need to enable searching inside file contents, I think it's not ON by default.
Anyways, A_ZoomFactor is defined in zscript/inventory/weapon.txt, here it is:
But looking at the code, there is no mouse movement scaling...
Anyways, A_ZoomFactor is defined in zscript/inventory/weapon.txt, here it is:
Code: Select all
action void A_ZoomFactor(double zoom = 1, int flags = 0)
{
let player = self.player;
if (player != NULL && player.ReadyWeapon != NULL)
{
zoom = 1 / clamp(zoom, 0.1, 50.0);
if (flags & 1)
{ // Make the zoom instant.
self.player.FOV = self.player.DesiredFOV * zoom;
}
if (flags & 2)
{ // Disable pitch/yaw scaling.
zoom = -zoom;
}
self.player.ReadyWeapon.FOVScale = zoom;
}
}
- Player701
-
- Posts: 1640
- Joined: Wed May 13, 2009 3:15 am
- Graphics Processor: nVidia with Vulkan support
- Contact:
Re: Changing mouse speed in ZScript
Note the following part of the code:
This logic handles the ZOOM_NOSCALETURNING flag. From the wiki:
Let's see how FOVScale actually works. It is handled in PlayerPawn.CheckFOV (gzdoom.pk3/zscript/shared/player.txt). The FOVScale value is used to smoothly alter the player's FOV, but before it is used, the value is turned absolute. There is the following comment about it:
Aha! So that's what we should be looking for. G_AddViewPitch and G_AddViewAngle are in g_game.cpp, and they indeed use the player's ReadyWeapon.FOVScale value to adjust the speed if FOVScale is negative. Unfortunately, this logic is hard-coded and altering the current behavior doesn't seem to be possible without changing the source code.
Conclusions:
Code: Select all
if (flags & 2)
{ // Disable pitch/yaw scaling.
zoom = -zoom;
}
So, this flag (0x2) is handled in A_ZoomFactor by setting the zoom to a negative value, which is in turn passed to ReadyWeapon.FOVScale. So it appears that FOVScale is not only responsible for gradual zooming but also for mouse sensitivity.ZDoom Wiki wrote:ZOOM_NOSCALETURNING: Player turning is normally scaled as well by this function. Use this flag to retain the player's unzoomed sensitivity while zoomed.
Let's see how FOVScale actually works. It is handled in PlayerPawn.CheckFOV (gzdoom.pk3/zscript/shared/player.txt). The FOVScale value is used to smoothly alter the player's FOV, but before it is used, the value is turned absolute. There is the following comment about it:
Code: Select all
// A negative scale is used to prevent G_AddViewAngle/G_AddViewPitch
// from scaling with the FOV scale.
desired *= abs(player.ReadyWeapon.FOVScale);
Conclusions:
- Player's mouse speed is tied to the player's ReadyWeapon.FOVScale. This means that altering it won't work without a weapon.
- To change the player's mouse speed you have to: A) give the player a weapon, B) set its FOVScale, C) override CheckFOV in your player class so that the player's FOV does not change.
Last edited by Player701 on Wed Nov 14, 2018 6:14 am, edited 4 times in total.
Re: Changing mouse speed in ZScript
A_ZoomFactor's view sensitivity scaling is hardcoded in g_game.cpp, in functions G_AddViewAngle and G_AddViewPitch. Here are the relevant lines:
You cannot hook in directly to these parts of the engine, but using the above information, you can extrapolate that all it's doing is multiplying the player's view and pitch with a multiplier (FOVScale in this case).
As for WHERE is the earliest point in the engine where you can intercept this via scripting... I don't have the answer. Maybe someone else knows.
Code: Select all
look = int(look * players[consoleplayer].ReadyWeapon->FOVScale);
yaw = int(yaw * players[consoleplayer].ReadyWeapon->FOVScale);
As for WHERE is the earliest point in the engine where you can intercept this via scripting... I don't have the answer. Maybe someone else knows.
- Caligari87
- Admin
- Posts: 6174
- Joined: Thu Feb 26, 2004 3:02 pm
- Preferred Pronouns: He/Him
- Contact:
Re: Changing mouse speed in ZScript
I'm pretty sure it's in virtual void MovePlayer() for angle and virtual void CheckPitch() for pitch (relevant line numbers linked). No idea if overriding those messes with prediction/interpolation at all.
- phantombeta
- Posts: 2088
- Joined: Thu May 02, 2013 1:27 am
- Operating System Version (Optional): Windows 10
- Graphics Processor: nVidia with Vulkan support
- Location: Brazil
Re: Changing mouse speed in ZScript
Overriding those shouldn't mess with the MP player prediction, as it simply runs PlayerThink, I believe, which uses these.Caligari87 wrote:I'm pretty sure it's in virtual void MovePlayer() for angle and virtual void CheckPitch() for pitch (relevant line numbers linked). No idea if overriding those messes with prediction/interpolation at all.