mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2026-08-15 13:04:36 +00:00
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.
This commit is contained in:
parent
cca4134e8b
commit
a3c918e946
14 changed files with 1866 additions and 65 deletions
55
MinecraftClient/Physics/MovementInput.cs
Normal file
55
MinecraftClient/Physics/MovementInput.cs
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue