Skip to main content
Typo
Source Link
LudoProf
  • 846
  • 3
  • 15
# Isolate horizontal components (so we don't slow a fall)
var vel2d := Vector2(velocity.x, velocity.z)

# Step the whole vector DEACC units toward (0, 0)
vel2d = vel2d.move_toward(Vector3Vector2.ZERO, DEACC)

# Unpack back into the original 3D velocity (preserving y)
velocity.x = vel2d.x
velocity.z = vel2d.y
# Isolate horizontal components (so we don't slow a fall)
var vel2d := Vector2(velocity.x, velocity.z)

# Step the whole vector DEACC units toward (0, 0)
vel2d = vel2d.move_toward(Vector3.ZERO, DEACC)

# Unpack back into the original 3D velocity (preserving y)
velocity.x = vel2d.x
velocity.z = vel2d.y
# Isolate horizontal components (so we don't slow a fall)
var vel2d := Vector2(velocity.x, velocity.z)

# Step the whole vector DEACC units toward (0, 0)
vel2d = vel2d.move_toward(Vector2.ZERO, DEACC)

# Unpack back into the original 3D velocity (preserving y)
velocity.x = vel2d.x
velocity.z = vel2d.y
Better formatting for mobile / narrow column
Source Link
LudoProf
  • 846
  • 3
  • 15

The "change" column also shows that our rate of deceleration is not constant: we decelerate more sharply when travelling diagonally, and let off the brakes a little as the velocity aligns with a coordinate axis. This is because decelerating by DEACC on each of two axes separately applies a delta-V with magnitude \$\sqrt{\text{DEACC}^2 + \text{DEACC}^2} = \sqrt{2}\cdot\text{DEACC}\$:

$$\|\Delta v\ \| = \sqrt{\text{DEACC}^2 + \text{DEACC}^2} = \sqrt{2}\cdot\text{DEACC}$$. 

That's 41.4% more than the delta-V we get when only one axis is changing.

If you want to take the behaviour you get when the velocity is pointing directly along the x or z axis, and make it consistent at all angles, then you can do it like this:

Applyneed to apply the deceleration to both components together, rather than separately:

The "change" column also shows that our rate of deceleration is not constant: we decelerate more sharply when travelling diagonally, and let off the brakes a little as the velocity aligns with a coordinate axis. This is because decelerating by DEACC on each of two axes separately applies a delta-V with magnitude \$\sqrt{\text{DEACC}^2 + \text{DEACC}^2} = \sqrt{2}\cdot\text{DEACC}\$. That's 41.4% more than the delta-V we get when only one axis is changing.

If you want to take the behaviour you get when the velocity is pointing directly along the x or z axis, and make it consistent at all angles, you can do it like this:

Apply the deceleration to both components together, rather than separately:

The "change" column also shows that our rate of deceleration is not constant: we decelerate more sharply when travelling diagonally, and let off the brakes a little as the velocity aligns with a coordinate axis. This is because decelerating by DEACC on each of two axes separately applies a delta-V with magnitude:

$$\|\Delta v\ \| = \sqrt{\text{DEACC}^2 + \text{DEACC}^2} = \sqrt{2}\cdot\text{DEACC}$$. 

That's 41.4% more than the delta-V we get when only one axis is changing.

If you want to take the behaviour you get when the velocity is pointing directly along the x or z axis, and make it consistent at all angles, then you need to apply the deceleration to both components together, rather than separately:

Extending table, noting inconsistent deceleration rate, improving explanation / headings, improving math notation
Source Link
LudoProf
  • 846
  • 3
  • 15

The "change" column also shows that our rate of deceleration is not constant: we decelerate more sharply when travelling diagonally, and let off the brakes a little as the velocity aligns with a coordinate axis. This is because decelerating by DEACC on each of two axes separately applies a delta-V with magnitude \$\sqrt{\text{DEACC}^2 + \text{DEACC}^2} = \sqrt{2}\cdot\text{DEACC}\$. That's 41.4% more than the delta-V we get when only one axis is changing.

Because x and z change in the same ratio each tick, we preserve the direction velocity is pointing in, eliminating the curving you were observing. These solutions also ensure your deceleration is consistent in every direction, rather than decelerating more sharply when moving on a 45° diagonal (when you reduce speed by DEACC on each axis, or sqrt(2)*DEACC overall, about 41.4% sharper than decelerating on a single axis)diagonally.

The "change" column also shows that our rate of deceleration is not constant: we decelerate more sharply when travelling diagonally, and let off the brakes a little as the velocity aligns with a coordinate axis.

Because x and z change in the same ratio each tick, we preserve the direction velocity is pointing in, eliminating the curving you were observing. These solutions also ensure your deceleration is consistent in every direction, rather than decelerating more sharply when moving on a 45° diagonal (when you reduce speed by DEACC on each axis, or sqrt(2)*DEACC overall, about 41.4% sharper than decelerating on a single axis).

The "change" column also shows that our rate of deceleration is not constant: we decelerate more sharply when travelling diagonally, and let off the brakes a little as the velocity aligns with a coordinate axis. This is because decelerating by DEACC on each of two axes separately applies a delta-V with magnitude \$\sqrt{\text{DEACC}^2 + \text{DEACC}^2} = \sqrt{2}\cdot\text{DEACC}\$. That's 41.4% more than the delta-V we get when only one axis is changing.

Because x and z change in the same ratio each tick, we preserve the direction velocity is pointing in, eliminating the curving you were observing. These solutions also ensure your deceleration is consistent in every direction, rather than decelerating more sharply when moving diagonally.

Extending table, noting inconsistent deceleration rate, improving explanation / headings
Source Link
LudoProf
  • 846
  • 3
  • 15
Loading
typo
Source Link
DMGregory
  • 140.8k
  • 23
  • 257
  • 401
Loading
Vertical independence, code corrections, adding non-linear options
Source Link
DMGregory
  • 140.8k
  • 23
  • 257
  • 401
Loading
Source Link
LudoProf
  • 846
  • 3
  • 15
Loading