Skip to content

bugfix: Holding CTRL key resets flying acceleration#863

Merged
rtm516 merged 1 commit intosmartcmd:mainfrom
bootsareme:bugfix/ctrl-fly
Mar 7, 2026
Merged

bugfix: Holding CTRL key resets flying acceleration#863
rtm516 merged 1 commit intosmartcmd:mainfrom
bootsareme:bugfix/ctrl-fly

Conversation

@bootsareme
Copy link
Contributor

Description

When flying in creative mode, attempting to hold down the CTRL key causes the player to fly slower rather than faster (like with double tapping W). This PR fixes that bug such that pressing CTRL will also make the player fly as fast as double tapping W

Changes

Previous Behavior

Holding CTRL slows the player down when flying.

Root Cause

The flying velocity ramp-up behavior is scaled using the following formula:

float scale = ((float)(SPRINT_DURATION - sprintTime))/10.0f;
where SPRINT_DURATION is a constant that is always 600. When holding CTRL, sprintTime always gets reset to 600. Therefore, scale = 0 which makes the player slow. Using a combination of tracepoints, I determined that setSprinting(true) sets sprintTime = SPRINT_DURATION, which means that while pressing CTRL one time will start the countdown here: holding the key will reset this countdown, meaning scale will never go above zero. I have determined that this line:
if (input->sprinting && onGround && enoughFoodToSprint && !isUsingItem() && !hasEffect(MobEffect::blindness) && !isSneaking())
is missing a check to see if the player is already in the sprinting state.

New Behavior

Holding CTRL now speeds the player up to full velocity when flying.

Fix Implementation

Added a check to make sure that setSprinting(true) was not called if the player is already "sprinting" when flying. setSprinting() causes the acceleration to start from zero. Therefore, if you hold down CTRL setSprinting(true) will be called repeatedly thus always slowing down the player when flying.

AI Use Disclosure

AI was only used to understand the quadratic acceleration code:

// Accelrate up to full speed if we are sprinting, moving in the direction of the view vector 
flyX = (float)viewVector->x * input->ya;
flyY = (float)viewVector->y * input->ya; 
flyZ = (float)viewVector->z * input->ya; 
float scale = ((float)(SPRINT_DURATION - sprintTime))/10.0f; 
scale = scale * scale; 
if ( scale > 1.0f ) scale = 1.0f; 
flyX *= scale; 
flyY *= scale; 
flyZ *= scale;

Related Issues

@rtm516 rtm516 merged commit 1be5faa into smartcmd:main Mar 7, 2026
1 check passed
@bootsareme bootsareme deleted the bugfix/ctrl-fly branch March 7, 2026 23:27
retroohmygod pushed a commit to retroohmygod/astrasmcfork that referenced this pull request Mar 8, 2026
piebotc pushed a commit to piebotc/LegacyEvolved that referenced this pull request Mar 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Creative fly Ctrl weird behavior

2 participants