AltFunctionUse (right click) causing a tick of delay between consecutive uses
See original GitHub issueDescription
With a weapon’s right-click use, there is a single tick of pause between consecutive uses, where the hand returns to resting position. At lower use speeds this makes the hand appear to glitch out, moving back and forth rapidly. Normally, with left click, the hand just stays out as long as the weapon is in use.
Steps to Reproduce
- Create a weapon with
override bool AltFunctionUse(Player player)
returning true, anditem.autoReuse
set to true inSetDefaults()
. - Run the game with the modded weapon active.
- Select the weapon and hold Right Click.
Expected behavior
There is 1 frame where nothing happens between uses of the weapon, the hand moving back to resting position and then back to the use animation.
Actual behavior
The hand should stay out, as left click does, and no delay should occur between uses.
Reproduction frequency
Every time, with any standard weapon with an altFunctionUse. This is most noticeable with useStyles 3 and 5, however.
Versions
tModLoader v0.10.1
Additional Information
It appears that this happens because the alternate function code is called near the end of the player update method, and there’s the check if (this.itemAnimation == 0 || PlayerInput.Triggers.JustPressed.MouseRight)
, the logical conclusion being that the code for using the weapon doesn’t run unless the player has already stopped swinging, causing the 1 tick of pause.
Issue Analytics
- State:
- Created 6 years ago
- Comments:8 (8 by maintainers)
Ah, you meant player.itemAnimation, sorry!
It’s a good idea to try setting it to 0, but sadly it didn’t work in either ModItem.CanUseItem, ModPlayer.PreUpdate or ModPlayer.PostUpdate.
However, after a lot of trial and error I got the following to work inside GetWeaponDamage! It’s a little hacky but it got the job done. It depends on GetWeaponDamage running every tick of the player’s useAnimation.
Edit 2: I suppose there is a much cleaner way to do it, by simply looping the animation back before it reaches 0 and replaying the use sound. It probably has its own issues; I think it effectively lowers the total useAnimation of the item by 1, so keep that in mind:
Edit 1: The bug has a related effect that makes it normally impossible to have an alternate use without autoReuse. Here is how you could fix that, inside CanUseItem:
These are probably not very good solutions, but there’s that for anyone who might be looking into this.
If there’s nothing else to be said, should we close the issue?
This was probably fixed by #2351 and related issues