Skip to content

Instantly share code, notes, and snippets.

@MartinZikmund
Created December 19, 2025 22:54
Show Gist options
  • Select an option

  • Save MartinZikmund/e2219ec011ac06204784dca99be05693 to your computer and use it in GitHub Desktop.

Select an option

Save MartinZikmund/e2219ec011ac06204784dca99be05693 to your computer and use it in GitHub Desktop.
if (_movementPointerId.HasValue)
{
var dx = _movementCurrent.X - _movementCenter.X;
var dy = _movementCurrent.Y - _movementCenter.Y;
var distance = Math.Sqrt(dx * dx + dy * dy);
var normalizedDistance = Math.Min(distance / JoystickRadius, 1.0);
if (normalizedDistance > DeadZone)
{
var angle = Math.Atan2(dy, dx);
var adjustedDistance = (normalizedDistance - DeadZone) / (1.0 - DeadZone);
// Forward/backward (Y axis, inverted)
forward = (float)(-Math.Sin(angle) * adjustedDistance);
// Strafe (X axis)
strafe = (float)(Math.Cos(angle) * adjustedDistance);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment