Changing mouse speed in ZScript

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!)

Post a reply

Smilies
:D :) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :geek: :ugeek: :!: :?: :idea: :arrow: :| :mrgreen: :3: :wub: >:( :blergh:
View more smilies

BBCode is OFF
Smilies are ON

Topic review
   

Expand view Topic review: Changing mouse speed in ZScript

Re: Changing mouse speed in ZScript

by phantombeta » Wed Nov 14, 2018 12:05 pm

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.

8-)
Overriding those shouldn't mess with the MP player prediction, as it simply runs PlayerThink, I believe, which uses these.

Re: Changing mouse speed in ZScript

by Caligari87 » Wed Nov 14, 2018 11:56 am

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.

8-)

Re: Changing mouse speed in ZScript

by Nash » Wed Nov 14, 2018 3:16 am

A_ZoomFactor's view sensitivity scaling is hardcoded in g_game.cpp, in functions G_AddViewAngle and G_AddViewPitch. Here are the relevant lines:

Code: Select all

look = int(look * players[consoleplayer].ReadyWeapon->FOVScale);
yaw = int(yaw * players[consoleplayer].ReadyWeapon->FOVScale);
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.

Re: Changing mouse speed in ZScript

by Player701 » Wed Nov 14, 2018 3:13 am

Note the following part of the code:

Code: Select all

if (flags & 2)
{ // Disable pitch/yaw scaling.
    zoom = -zoom;
}
This logic handles the ZOOM_NOSCALETURNING flag. From the wiki:
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.
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.

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);
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:
  1. Player's mouse speed is tied to the player's ReadyWeapon.FOVScale. This means that altering it won't work without a weapon.
  2. 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.
This is a kind of a hack, since you need a weapon to achieve the desired effect, but logically, a weapon shouldn't be required for this. It might be a good idea for a PR to add fields to PlayerPawn / PlayerInfo that can be used to adjust the player's horizontal and vertical mouse speed instead. EDIT: Or, even better, add a virtual function to Inventory to get the scaling factors so that they can be combined. This is also better than changing values directly on the player actor. The problem is, the developers appear to have a strong opinion against any kind of "interface screw", so I'm not sure if they will approve this. Inverting the player movement to simulate a drunk player would be fun, though.

Re: Changing mouse speed in ZScript

by ramon.dexter » Wed Nov 14, 2018 3:06 am

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:

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;
		}
	}
But looking at the code, there is no mouse movement scaling...

Re: Changing mouse speed in ZScript

by Jekyll Grim Payne » Wed Nov 14, 2018 2:33 am

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...)

Re: Changing mouse speed in ZScript

by Enjay » Tue Nov 13, 2018 2:23 pm

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.

Changing mouse speed in ZScript

by Jekyll Grim Payne » Tue Nov 13, 2018 1:31 pm

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.

Top