Skip to content

Move physics to a separate file - #1775

Merged
IntegratedQuantum merged 13 commits into
PixelGuys:masterfrom
codemob-dev:1728-surface-physics
Aug 18, 2025
Merged

IntegratedQuantum merged 13 commits into
PixelGuys:masterfrom
codemob-dev:1728-surface-physics

Conversation

@codemob-dev

Copy link
Copy Markdown
Contributor

Progress towards #1728

@codemob-dev
codemob-dev marked this pull request as ready for review August 17, 2025 18:25
@codemob-dev

Copy link
Copy Markdown
Contributor Author

@IntegratedQuantum Should keyboard input be in physics.zig or should it be handled separately in game.zig?

@IntegratedQuantum

Copy link
Copy Markdown
Member

The physics system should handle one thing, and one thing only: Physics

@codemob-dev
codemob-dev marked this pull request as draft August 17, 2025 18:29
@IntegratedQuantum

IntegratedQuantum commented Aug 17, 2025 •

Copy link
Copy Markdown
Member

Ideally we want to be able to reuse the same system for entities, which will have different input

@codemob-dev
codemob-dev marked this pull request as ready for review August 17, 2025 19:17
Comment thread src/game.zig
const walkingSpeed: f64 = if(Player.crouching) 2 else 4;
if(KeyBoard.key("forward").value > 0.0) {
if(KeyBoard.key("sprint").pressed and !Player.crouching) {
if(KeyBoard.key("backward").value > 0.0) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Git is really struggling to handle the diff here, lol

@codemob-dev

Copy link
Copy Markdown
Contributor Author

Ready for review

Comment thread src/game.zig
pub var jumpCoyote: f64 = 0;
const jumpCooldownConstant = 0.3;
const jumpCoyoteTimeConstant = 0.100;
pub const jumpCooldownConstant = 0.3;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally it also shouldn't access these constants from the player, different entities may have different jump heights.
But that should be done in a separate PR.
Issue: #1778

Comment thread src/game.zig
var acc = Vec3d{0, 0, 0};
if(!Player.isFlying.load(.monotonic)) {
acc[2] = -effectiveGravity;
var acc = Vec3d{0, 0, 0};

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally in the future, the acceleration should be calculated entirely inside the physics code, the entity should only give it a desired velocity value or something like that.

Comment thread src/game.zig Resolved
Comment thread src/game.zig Resolved
Comment thread src/game.zig Resolved
Comment thread src/physics.zig Resolved

@IntegratedQuantum IntegratedQuantum left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the future it also might be worth considering to move collision outside of game as well, either also in physics.zig, or just into a separate file physics/collision.zig

@IntegratedQuantum
IntegratedQuantum merged commit 5b5fc4b into PixelGuys:master Aug 18, 2025
@codemob-dev
codemob-dev deleted the 1728-surface-physics branch October 23, 2025 14:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants