Skip to content

Commit

Permalink
make friction more accurate
Browse files Browse the repository at this point in the history
  • Loading branch information
OneAvargeCoder193 committed Jan 26, 2025
1 parent fd9372a commit 8a4fe81
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/game.zig
Original file line number Diff line number Diff line change
Expand Up @@ -299,11 +299,23 @@ pub const collision = struct {
while (y <= maxY) : (y += 1) {
const _block = if(side == .client) main.renderer.mesh_storage.getBlock(x, y, z)
else main.server.world.?.getBlock(x, y, z);
const min = @max(Vec2d{@floatFromInt(x), @floatFromInt(y)}, vec.xy(boundingBox.min));
const max = @min(Vec2d{@floatFromInt(x + 1), @floatFromInt(y + 1)}, vec.xy(boundingBox.max));
const area = (max[0] - min[0]) * (max[1] - min[1]);


if (_block) |block| {
const blockPos: Vec3d = .{@floatFromInt(x), @floatFromInt(y), @floatFromInt(z)};

const blockBox: Box = .{
.min = blockPos + @as(Vec3d, @floatCast(main.models.models.items[block.mode().model(block)].min)),
.max = blockPos + @as(Vec3d, @floatCast(main.models.models.items[block.mode().model(block)].max)),
};

if (boundingBox.min[0] > blockBox.max[0] or boundingBox.max[0] < blockBox.min[0] or
boundingBox.min[1] > blockBox.max[1] or boundingBox.max[1] < blockBox.min[1] or
boundingBox.min[2] > blockBox.max[2] or boundingBox.max[2] < blockBox.min[2]) {
continue;
}

const area = (blockBox.max[0] - blockBox.min[0]) * (blockBox.max[1] - blockBox.min[1]);

if (block.collide()) {
totalArea += area;
friction += area * @as(f64, @floatCast(block.friction()));
Expand Down Expand Up @@ -400,9 +412,6 @@ pub const Player = struct { // MARK: Player

pub var currentFriction: f32 = 0;

pub var maxHealth: f32 = 8;
pub var health: f32 = 4.5;

pub var onGround: bool = false;
pub var jumpCooldown: f64 = 0;
const jumpCooldownConstant = 0.3;
Expand Down

0 comments on commit 8a4fe81

Please sign in to comment.