Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sprint-flying backwards and sidewards #705

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 45 additions & 6 deletions src/game.zig
Original file line number Diff line number Diff line change
Expand Up @@ -684,16 +684,55 @@ pub fn update(deltaTime: f64) void { // MARK: update()
}
}
if(KeyBoard.key("backward").pressed) {
movementSpeed = @max(movementSpeed, 4);
movementDir += forward*@as(Vec3d, @splat(-4));
if(KeyBoard.key("sprint").pressed) {
if(Player.isGhost.load(.monotonic)) {
movementSpeed = @max(movementSpeed, 128);
movementDir += forward*@as(Vec3d, @splat(-128));
} else if(Player.isFlying.load(.monotonic)) {
movementSpeed = @max(movementSpeed, 32);
movementDir += forward*@as(Vec3d, @splat(-32));
} else {
movementSpeed = @max(movementSpeed, 4);
movementDir += forward*@as(Vec3d, @splat(-4));
}
} else {
movementSpeed = @max(movementSpeed, 4);
movementDir += forward*@as(Vec3d, @splat(-4));
}
}
if(KeyBoard.key("left").pressed) {
movementSpeed = @max(movementSpeed, 4);
movementDir += right*@as(Vec3d, @splat(4));
if(KeyBoard.key("sprint").pressed) {
if(Player.isGhost.load(.monotonic)) {
movementSpeed = @max(movementSpeed, 128);
movementDir += right*@as(Vec3d, @splat(128));
} else if(Player.isFlying.load(.monotonic)) {
movementSpeed = @max(movementSpeed, 32);
movementDir += right*@as(Vec3d, @splat(32));
} else {
movementSpeed = @max(movementSpeed, 4);
movementDir += right*@as(Vec3d, @splat(4));
}
} else {
movementSpeed = @max(movementSpeed, 4);
movementDir += right*@as(Vec3d, @splat(4));
}
}
if(KeyBoard.key("right").pressed) {
movementSpeed = @max(movementSpeed, 4);
movementDir += right*@as(Vec3d, @splat(-4));
if(KeyBoard.key("sprint").pressed) {
if(Player.isGhost.load(.monotonic)) {
movementSpeed = @max(movementSpeed, 128);
movementDir += right*@as(Vec3d, @splat(-128));
} else if(Player.isFlying.load(.monotonic)) {
movementSpeed = @max(movementSpeed, 32);
movementDir += right*@as(Vec3d, @splat(-32));
} else {
movementSpeed = @max(movementSpeed, 4);
movementDir += right*@as(Vec3d, @splat(-4));
}
} else {
movementSpeed = @max(movementSpeed, 4);
movementDir += right*@as(Vec3d, @splat(-4));
}
Copy link
Member

@IntegratedQuantum IntegratedQuantum Sep 9, 2024

Choose a reason for hiding this comment

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

I think there is a more elegant solution, that doesn't involve copying the same code 4 times, if you use movementSpeed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So, something like what I'm about to commit? It does cause the player to be able to sprint in the directions on ground.

Copy link
Member

Choose a reason for hiding this comment

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

KInd of. But you should readd a special case when on the ground.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did that, that also added diagonal sprinting like in Minecraft.

Copy link
Member

Choose a reason for hiding this comment

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

Honestly, I think this diagonal sprinting feels wrong. Can't you just go back to the previous logic when not flying?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just tried that and I cant seem to get it to work.

Copy link
Member

Choose a reason for hiding this comment

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

Any progress on this or have you given up?

}
if(KeyBoard.key("jump").pressed) {
if(Player.isFlying.load(.monotonic)) {
Expand Down
Loading