collision refactor

This commit is contained in:
maxwes08
2026-03-24 00:14:17 +01:00
parent 9ffda6f5af
commit 24ca4288af
4 changed files with 242 additions and 140 deletions

View File

@@ -10,7 +10,7 @@ namespace Voxel
public readonly float mouseCooldown = 0.2f;
private int _blockIndex = 0;
private double _tickTime = 0;
private int _jumpTicks = 0;
private Blocks _selectedBlock = Blocks.OakPlanks;
private Vector3 previousPosition;
@@ -40,8 +40,10 @@ namespace Voxel
_world.SetBlock(x, y, z, Blocks.Air);
}
public new void Tick()
public void Tick()
{
if (_jumpTicks > 0) _jumpTicks--;
_world.UpdateChunkLoading(Position);
previousPosition = Position;
@@ -58,12 +60,6 @@ namespace Voxel
if (Input.GetKey(Keys.D))
sidewards = 1;
if (Input.GetKey(Keys.Space) && OnGround)
{
Velocity = new Vector3(Velocity.X, 0.42f, Velocity.Z);
OnGround = false;
}
if (Input.GetMouseButton(MouseButton.Right) && lastClick == 0)
{
lastClick = mouseCooldown;
@@ -78,8 +74,30 @@ namespace Voxel
BreakBlock();
}
if (Position.Y < -8)
{
Position.Y = 64;
Velocity.Y = 0;
}
ApplyWalkSpeed(sidewards, forwards);
base.Tick();
if (Input.GetKey(Keys.Space))
{
if (OnGround && _jumpTicks == 0)
{
Jump();
_jumpTicks = 10;
}
}
else _jumpTicks = 0;
}
public void Jump()
{
Velocity = new Vector3(Velocity.X, 0.42f, Velocity.Z);
OnGround = false;
}
public void Update(float deltaTime, float alpha)
@@ -125,7 +143,7 @@ namespace Voxel
}
else
{
Vector3 groundAccel = worldDir * 0.1f * M_t;
Vector3 groundAccel = worldDir * 0.13f * M_t;
Velocity = new Vector3(Velocity.X * groundMultiplier + groundAccel.X,
Velocity.Y,
Velocity.Z * groundMultiplier + groundAccel.Z);