Minecraft-Console-Client/MinecraftClient/Physics/MovementInput.cs
BruceChen a3c918e946 feat: implement physics engine for player movement and collision detection
- Introduced a comprehensive physics engine that replicates Minecraft's movement mechanics, including player input handling, gravity, and collision detection.
- Added classes for player physics, movement input, and collision detection, ensuring accurate simulation of player interactions with the game world.
- Integrated AABB (Axis-Aligned Bounding Box) structures for precise collision detection against blocks.
- Enhanced movement capabilities with support for jumping, sneaking, and sprinting, along with step-up mechanics for navigating terrain.

These changes significantly improve the realism and responsiveness of player movement within the game environment.
2026-03-22 15:29:22 +08:00

55 lines
1.4 KiB
C#

using System;
namespace MinecraftClient.Physics
{
/// <summary>
/// Represents movement input state, equivalent to vanilla ClientInput / KeyboardInput.
/// </summary>
public class MovementInput
{
public bool Forward;
public bool Back;
public bool Left;
public bool Right;
public bool Jump;
public bool Sneak;
public bool Sprint;
/// <summary>
/// Get the raw input vector (xxa, zza) before rotation.
/// Forward = +zza, Back = -zza, Left = +xxa, Right = -xxa.
/// Then normalized if magnitude > 1.
/// </summary>
public (float xxa, float zza) GetMoveVector()
{
float xxa = 0;
float zza = 0;
if (Forward) zza += 1.0f;
if (Back) zza -= 1.0f;
if (Left) xxa += 1.0f;
if (Right) xxa -= 1.0f;
float lenSqr = xxa * xxa + zza * zza;
if (lenSqr > 1.0f)
{
float len = MathF.Sqrt(lenSqr);
xxa /= len;
zza /= len;
}
return (xxa, zza);
}
public void Reset()
{
Forward = false;
Back = false;
Left = false;
Right = false;
Jump = false;
Sneak = false;
Sprint = false;
}
}
}