Physics: Difference between revisions
Created page with "Everybody Edits includes a physics engine to manage the movement of its players and interactions with player inputs and world blocks. ==Source code files== Inside Everybody Edits Offline source: {| class="wikitable" |Config.as |constants used in the physics engine (such as drag values, jump height, gravity values, delayed block queue, etc.) |- |Me.as |touchBlock function (handles most non-solid collisions, such as interactions with coins, reset block, sound blocks..." |
No edit summary |
||
| Line 14: | Line 14: | ||
|Player.as | |Player.as | ||
|tick function (handles most of the physics logic) | |tick function (handles most of the physics logic) | ||
|- | |||
|SynchronizedObject.as | |||
|defines constants based on Config.as, and performs confusing multiplications/divisions by physics_variable_multiplyer | |||
|- | |- | ||
|World.as | |World.as | ||
| Line 39: | Line 42: | ||
In case of slippery>0, jump height is multiplied by 0.88, it also affects drag computation. | In case of slippery>0, jump height is multiplied by 0.88, it also affects drag computation. | ||
==Acceleration values== | |||
Acceleration (modifier) values are used to react to player's horizontal/vertical inputs and gravity. Like with coordinates, accelerations are stored in double precision floating point and are in pixels. | |||
{| class="wikitable | |||
!name | |||
!definition | |||
|- | |||
|physics_variable_multiplyer | |||
|7.752 | |||
|- | |||
|physics_jump_height | |||
|26 | |||
|- | |||
|physics_gravity | |||
|2 | |||
|- | |||
|physics_water_buoyancy | |||
| -.5 | |||
|- | |||
|physics_mud_buoyancy | |||
|.4 | |||
|- | |||
|physics_lava_buoyancy | |||
|.2 | |||
|- | |||
|physics_toxic_buoyancy | |||
| -.4 | |||
|} | |||
===Gravitational acceleration (mox, moy)=== | |||
The delayed block is evaluated: | |||
<ul> | |||
<li>dots, slow dots, and boosts set both axes to 0</li> | |||
<li>gravity arrows set one of the axes to ±physics_gravity and ignore gravity effect</li> | |||
<li>liquids (water/mud/lava/toxic) sets vertical axis to the respective buoyancy value</li> | |||
<li>default gravity sets vertical axis to physics_gravity</li> | |||
<li>all non-gravity-arrow cases rotate axes depending on gravity effect (or set to 0 in neutral gravity effect)</li> | |||
</ul> | |||
Then both axes are multiplied with the gravity multiplier (all multipliers cumulative): | |||
<ul> | |||
<li>1 in default gravity</li> | |||
<li>multiplied by 0.15 in low gravity effect</li> | |||
<li>multiplied by world gravity</li> | |||
<ul> | |||
<li>1 by default</li> | |||
<li>0.159999996423721 for low gravity world (single precision float 3E23D70A from eelvl file)</li> | |||
<li>opening non-default gravity world in [[EEO]] unlocks configurable world gravity from 10%—300% in increments of 1%</li> | |||
</ul> | |||
</ul> | |||
===Lateral acceleration (mx, my)=== | |||
The horizontal/vertical fields (-1, 0, or 1) are applied on axes where the gravitational acceleration is 0 (except for when delayed block is a liquid, in which case both axes are applied). | |||
Then both axes are multiplied with the speed multiplier (all multipliers cumulative): | |||
<ul> | |||
<li>1 in default speed</li> | |||
<li>multiplied by 1.5 in high speed effect</li> | |||
<li>multiplied by 0.6 in low speed effect</li> | |||
<li>multiplied by 0.6 in zombie</li> | |||
</ul> | |||
===Total acceleration (_modifierX, _modifierY)=== | |||
The sum of gravitational and lateral accelerations (mox+mx, moy+my) is assigned to modifierX and modifierY (no underscore), but the setter in SynchronizedObject.as additionally implies a division by physics_variable_multiplyer (for example default sideways movement accelerates by 1/7.752, not 1). The resulting values _modifierX and _modifierY are then directly added to _speedX and _speedY before computing drag. | |||
==Drag values== | ==Drag values== | ||
| Line 126: | Line 197: | ||
Boosts force the speed to be -16 or 16 on the axis they apply to, though the other axis still follows the usual computations. | Boosts force the speed to be -16 or 16 on the axis they apply to, though the other axis still follows the usual computations. | ||
==Applying speed to position== | |||
The physics engine slices player's speed on both axes at pixel boundaries, then alternates between horizontal and vertical chunks of the speed (pixel by pixel, which may be fractional for first and last chunk) until both axes either complete the speed or collide with a block. Collision causes the speed on that axis to be set to 0 and that axis's position of the step to be reverted, but the remainder of the speed is still processed in subsequent iterations until the loop ends. The exception to the pixel boundary slicing rule is that if the player moves up or left from an integer pixel coordinate and current block is not a boost, the full speed component is applied in one step (if player jumps and on the next tick moves away from ceiling, player may get blocked by the ceiling after first horizontal chunk and after subsequent horizontal speed chunk immediately moved up by full jump speed, but vertical speed is set to 0, causing the jump to only last 1 tick). In case of boosts, moving up or left from integer pixel coordinate causes the first step to be 0, then subsequent steps are pixel by pixel as usual. | |||
==Jump value== | |||
Jump effectively overwrites speed along the gravity axis with physics_gravity*physics_jump_height*jumpMultiplier/physics_variable_multiplyer where jump multiplier is the following (all multipliers cumulative): | |||
<ul> | |||
<li>1 in default jump</li> | |||
<li>multiplied by 1.3 in high jump effect</li> | |||
<li>multiplied by 0.75 in low jump effect</li> | |||
<li>multiplied by 0.75 in zombie</li> | |||
<li>multiplied by 0.88 if slippery>0</li> | |||
</ul> | |||
The jump speed is applied after the speed has been applied to player's position, so the jump speed is first applied on the next tick after player's jump input. | |||
Latest revision as of 19:15, 2 November 2026
Everybody Edits includes a physics engine to manage the movement of its players and interactions with player inputs and world blocks.
Source code files
Inside Everybody Edits Offline source:
| Config.as | constants used in the physics engine (such as drag values, jump height, gravity values, delayed block queue, etc.) |
| Me.as | touchBlock function (handles most non-solid collisions, such as interactions with coins, reset block, sound blocks, crown, switches, invisible gravity, diamond/cake/hologram, checkpoint, win, god enable, minimap enable, keys, effects, lava) |
| Player.as | tick function (handles most of the physics logic) |
| SynchronizedObject.as | defines constants based on Config.as, and performs confusing multiplications/divisions by physics_variable_multiplyer |
| World.as | overlaps function (handles collision with solid blocks, including doors/gates, half blocks, one-way, and secret blocks) |
Timing
EE physics runs at 100tps (100 ticks per second), meaning that each physics tick takes 0.01 seconds.
Inputs
On each tick, the arrow/WASD keys and space keys are evaluated. The arrow/WASD inputs are converted into horizontal and vertical components of -1, 0, or 1, in which left+right and up+down inputs cancel out to 0. Space may be pressed independently of other keys.
Coordinates
Player's coordinates are represented in double precision floating point. The position [0, 0] corresponds to the top left block, and increases to the right and downwards in pixels (16 pixels per block on both axes). The bottom right position is [(width-1)*16, (height-1)*16].
Current and delayed blocks
The current block is determined by dividing player's position by 16 and rounding it (round to nearest, halfway values round up), except for down half or right half block, which decrement vertical or horizontal position of current block respectively.
The delayed block corresponds to current block from second previous tick (therefore delayed by 2 ticks from current block), unless the current block is a gravity dot or climbable/slow dot, in which case the current block is pushed to the queue a second time (effectively making delayed block only delayed by 1 tick), resulting in dots having a slightly faster reaction than other gravities.
Slippery field
First, the current_below block is determined (only used for computing slippery value). It follows the gravity direction inside the current block (following player's gravity if current is not a gravity arrow) and offsets by 1 from the current block to determine the current_below block. However, invisible right arrow (413), down arrow (1518, 1519), and invisible dot (414) are ignored, dot (4) is interpreted as a down offset, and neutral gravity (flipGravity==4) is interpreted as a right offset.
The slippery value is initialized to 0. It is set to 2 if current_below is an ice block and current is not a dot or climbable/slow dot. Otherwise, it is set to 0 if current_below is solid. Otherwise, it is set to 0.2 less than previous slippery value.
In case of slippery>0, jump height is multiplied by 0.88, it also affects drag computation.
Acceleration values
Acceleration (modifier) values are used to react to player's horizontal/vertical inputs and gravity. Like with coordinates, accelerations are stored in double precision floating point and are in pixels.
| name | definition |
|---|---|
| physics_variable_multiplyer | 7.752 |
| physics_jump_height | 26 |
| physics_gravity | 2 |
| physics_water_buoyancy | -.5 |
| physics_mud_buoyancy | .4 |
| physics_lava_buoyancy | .2 |
| physics_toxic_buoyancy | -.4 |
Gravitational acceleration (mox, moy)
The delayed block is evaluated:
- dots, slow dots, and boosts set both axes to 0
- gravity arrows set one of the axes to ±physics_gravity and ignore gravity effect
- liquids (water/mud/lava/toxic) sets vertical axis to the respective buoyancy value
- default gravity sets vertical axis to physics_gravity
- all non-gravity-arrow cases rotate axes depending on gravity effect (or set to 0 in neutral gravity effect)
Then both axes are multiplied with the gravity multiplier (all multipliers cumulative):
- 1 in default gravity
- multiplied by 0.15 in low gravity effect
- multiplied by world gravity
- 1 by default
- 0.159999996423721 for low gravity world (single precision float 3E23D70A from eelvl file)
- opening non-default gravity world in EEO unlocks configurable world gravity from 10%—300% in increments of 1%
Lateral acceleration (mx, my)
The horizontal/vertical fields (-1, 0, or 1) are applied on axes where the gravitational acceleration is 0 (except for when delayed block is a liquid, in which case both axes are applied).
Then both axes are multiplied with the speed multiplier (all multipliers cumulative):
- 1 in default speed
- multiplied by 1.5 in high speed effect
- multiplied by 0.6 in low speed effect
- multiplied by 0.6 in zombie
Total acceleration (_modifierX, _modifierY)
The sum of gravitational and lateral accelerations (mox+mx, moy+my) is assigned to modifierX and modifierY (no underscore), but the setter in SynchronizedObject.as additionally implies a division by physics_variable_multiplyer (for example default sideways movement accelerates by 1/7.752, not 1). The resulting values _modifierX and _modifierY are then directly added to _speedX and _speedY before computing drag.
Drag values
Drag values are used for multiplicative deceleration of player's speed.
| name | definition | floating point result |
|---|---|---|
| physics_ms_per_tick | 10 | 10 |
| physics_base_drag | Math.pow(.9981,physics_ms_per_tick) * 1.00016093 | 0.9813195279915707 |
| physics_ice_no_mod_drag | Math.pow(.9993,physics_ms_per_tick) * 1.00016093 | 0.9931818159222691 |
| physics_ice_drag | Math.pow(.9998,physics_ms_per_tick) * 1.00016093 | 0.9981624074698557 |
| physics_no_modifier_drag | Math.pow(.9900,physics_ms_per_tick) * 1.00016093 | 0.9045276172161356 |
| physics_water_drag | Math.pow(.9950,physics_ms_per_tick) * 1.00016093 | 0.9512631926190678 |
| physics_mud_drag | Math.pow(.9750,physics_ms_per_tick) * 1.00016093 | 0.7764545555823221 |
| physics_lava_drag | Math.pow(.9800,physics_ms_per_tick) * 1.00016093 | 0.8172042984143593 |
| physics_toxic_drag | Math.pow(.9900,physics_ms_per_tick) * 1.00016093 | 0.9045276172161356 |
The speed is added with the sum of lateral acceleration (performed with player's horizontal/vertical movements, ignoring movements along the axis of gravity), and gravitational acceleration (performed by current arrow or world gravity).
Then, using the drag constants, drag is applied on each axis as follows (first true condition applies):
| case | resulting speed |
|---|---|
| used if current block is climbable/slow dot (except god mode) not used if slippery<=0 (unless in god mode) used if lateral acceleration along the axis is 0 and gravity is on perpendicular axis used if speed and lateral acceleration along the axis are non-zero and of opposite signs |
speed*physics_base_drag*physics_no_modifier_drag |
| used if current block is water | speed*physics_base_drag*physics_water_drag |
| used if current block is mud | speed*physics_base_drag*physics_mud_drag |
| used if current block is lava | speed*physics_base_drag*physics_lava_drag |
| used if current block is toxic | speed*physics_base_drag*physics_toxic_drag |
| used if slippery>0 (except god mode), lateral acceleration along the axis is non-zero, and speed along the axis is zero or same sign as lateral movement | speed*physics_base_drag |
| used if slippery>0 (except god mode), lateral acceleration along the axis is 0 | speed*physics_ice_no_mod_drag |
| used if slippery>0 (except god mode), speed and lateral acceleration along the axis are non-zero and of opposite signs | speed*physics_ice_no_mod_drag*physics_ice_drag |
| used if none of the above | speed*physics_base_drag |
After computing drag on each axis, the speed is capped to a minimum of -16 and maximum of 16.
Speeds less than 0.0001 and greater than -0.0001 are set to 0. That's when the player will start falling on hovers if not moving (prior to that, it can stay in hover if within 0.2 pixels of block due to auto-align), or will be able to jump on a Tight-fit (which is why it takes more time to perform an Ice Tight-fit due to the ice drag being closer to 1).
Boosts force the speed to be -16 or 16 on the axis they apply to, though the other axis still follows the usual computations.
Applying speed to position
The physics engine slices player's speed on both axes at pixel boundaries, then alternates between horizontal and vertical chunks of the speed (pixel by pixel, which may be fractional for first and last chunk) until both axes either complete the speed or collide with a block. Collision causes the speed on that axis to be set to 0 and that axis's position of the step to be reverted, but the remainder of the speed is still processed in subsequent iterations until the loop ends. The exception to the pixel boundary slicing rule is that if the player moves up or left from an integer pixel coordinate and current block is not a boost, the full speed component is applied in one step (if player jumps and on the next tick moves away from ceiling, player may get blocked by the ceiling after first horizontal chunk and after subsequent horizontal speed chunk immediately moved up by full jump speed, but vertical speed is set to 0, causing the jump to only last 1 tick). In case of boosts, moving up or left from integer pixel coordinate causes the first step to be 0, then subsequent steps are pixel by pixel as usual.
Jump value
Jump effectively overwrites speed along the gravity axis with physics_gravity*physics_jump_height*jumpMultiplier/physics_variable_multiplyer where jump multiplier is the following (all multipliers cumulative):
- 1 in default jump
- multiplied by 1.3 in high jump effect
- multiplied by 0.75 in low jump effect
- multiplied by 0.75 in zombie
- multiplied by 0.88 if slippery>0
The jump speed is applied after the speed has been applied to player's position, so the jump speed is first applied on the next tick after player's jump input.