Untitled

 avatar
unknown
java
6 months ago
1.9 kB
3
Indexable
for each tick {
	if (strafing || forwarding) { /* movement key pressed */
		if (strafing && forwarding) { /* 45° */
			if (sneaking) {
				input_vec = (±0.294, 0, ±0.294);
			}
			else {
				input_vec = (±0.707, 0, ±0.707); /* speed capping via normalization, i.e. v/norm(v) */
			}
		}
		else { /* standard forward or strafe */
			if (sneaking) {
				input_vec = (±0.294, 0, 0); /* or (0, 0, ±0.294); */
			}
			else {
				input_vec = (±0.98, 0, 0); /* or (0, 0, ±0.98); */
			}
		}
		/*
		 * X xor Z sneaking speed factor is 0.294b/s
		 * 45°                "             0.416b/s
		 *     => when sneaking, 45° is sqrt(2) faster than normal sneaking - pythagore without capping
		 *
		 * standard (X xor Z) speed factor is 0.98b/s
		 * 45° movement is 1b/s (speed is capped)
		 *     => without sneaking, 45° is only, but nevertheless, 2% faster than normal movement
		 */

		/*
		 * slipperiness:
		 *   0.600 standard
		 *   0.980 ice / packed ice
		 *   0.989 blue ice
		 */
		if (onGround) {
			input_vec *= 0.1 * (0.6/slipperiness)^3; /* more slippery -> inputs contribute less to movement */
		}
		else { /* in air */
			input_vec *= 0.02;
		}

		/* sprinting is first applied here, so doesn't get capped */
		if (sprinting) {
			input_vec *= 1.3;
		}

		delta_pos += projectview(input_vec, rotationYaw); /* speed from previous tick is updated from current inputs */
	}

	/* delta_pos is like speed*tick_duration, so Δpos = v Δt */
	pos += delta_pos;

	/* speed update from the environment for the next tick: */

	delta_pos[1] -= 0.08; /* constant gravity accel, 32b/s^2! */
	delta_pos[1] *= 0.98; /* exponential Y speed damping from air drag */

	if (onGround) {
		delta_pos[0|2] *= 0.91 * slipperiness; /* exponential X/Z speed damping from ground friction => more slippery -> speed/inertia is kept more */
	}
	else {
		delta_pos[0|2] *= 0.91 /* exponential X/Z speed damping from air drag, more than Y! */
	}
}
Editor is loading...
Leave a Comment