Cleaned up recoil mechanic to be applied with a delta value instead of absolute.
This commit is contained in:
parent
a1c1aad065
commit
492b9f66aa
|
@ -1,7 +1,7 @@
|
|||
package nl.andrewl.aos2_client;
|
||||
|
||||
import nl.andrewl.aos2_client.config.ClientConfig;
|
||||
import nl.andrewl.aos2_client.control.*;
|
||||
import nl.andrewl.aos2_client.control.InputHandler;
|
||||
import nl.andrewl.aos2_client.model.Chat;
|
||||
import nl.andrewl.aos2_client.model.ClientPlayer;
|
||||
import nl.andrewl.aos2_client.model.OtherPlayer;
|
||||
|
@ -200,12 +200,13 @@ public class Client implements Runnable {
|
|||
if (soundManager != null) {
|
||||
soundManager.play("chat", 1, myPlayer.getEyePosition(), myPlayer.getVelocity());
|
||||
}
|
||||
} else if (msg instanceof ClientOrientationUpdateMessage orientationUpdateMessage) {
|
||||
} else if (msg instanceof ClientRecoilMessage recoil) {
|
||||
runLater(() -> {
|
||||
myPlayer.setOrientation(orientationUpdateMessage.x(), orientationUpdateMessage.y());
|
||||
myPlayer.setOrientation(myPlayer.getOrientation().x + recoil.dx(), myPlayer.getOrientation().y + recoil.dy());
|
||||
if (gameRenderer != null) {
|
||||
gameRenderer.getCamera().setOrientationToPlayer(myPlayer);
|
||||
}
|
||||
communicationHandler.sendDatagramPacket(ClientOrientationState.fromPlayer(myPlayer));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,8 +55,10 @@ public class PlayerInputKeyCallback implements GLFWKeyCallbackI {
|
|||
|
||||
case GLFW_KEY_T -> inputHandler.enableChatting();
|
||||
case GLFW_KEY_SLASH -> {
|
||||
inputHandler.enableChatting();
|
||||
inputHandler.appendToChat("/");
|
||||
if (!inputHandler.isChatting()) {
|
||||
inputHandler.enableChatting();
|
||||
inputHandler.appendToChat("/");
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (action == GLFW_REPEAT) {
|
||||
|
|
|
@ -55,11 +55,7 @@ public class PlayerViewCursorCallback implements GLFWCursorPosCallbackI {
|
|||
camera.setOrientationToPlayer(client.getMyPlayer());
|
||||
long now = System.currentTimeMillis();
|
||||
if (lastOrientationUpdateSentAt + ORIENTATION_UPDATE_LIMIT < now) {
|
||||
ForkJoinPool.commonPool().submit(() -> comm.sendDatagramPacket(new ClientOrientationState(
|
||||
client.getMyPlayer().getId(),
|
||||
client.getMyPlayer().getOrientation().x,
|
||||
client.getMyPlayer().getOrientation().y
|
||||
)));
|
||||
ForkJoinPool.commonPool().submit(() -> comm.sendDatagramPacket(ClientOrientationState.fromPlayer(client.getMyPlayer())));
|
||||
lastOrientationUpdateSentAt = now;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -369,10 +369,10 @@ public class GuiRenderer {
|
|||
nvgTextAlign(vgId, NVG_ALIGN_LEFT | NVG_ALIGN_TOP);
|
||||
nvgFillColor(vgId, GuiUtils.rgba(1, 1, 1, 1, colorA));
|
||||
var pos = client.getMyPlayer().getPosition();
|
||||
nvgText(vgId, 5, y, String.format("Pos: x=%.3f, y=%.3f, z=%.3f", pos.x, pos.y, pos.z));
|
||||
nvgText(vgId, 5, y, String.format("Pos: dx=%.3f, dy=%.3f, z=%.3f", pos.x, pos.y, pos.z));
|
||||
y += 12;
|
||||
var vel = client.getMyPlayer().getVelocity();
|
||||
nvgText(vgId, 5, y, String.format("Vel: x=%.3f, y=%.3f, z=%.3f, speed=%.3f", vel.x, vel.y, vel.z, vel.length()));
|
||||
nvgText(vgId, 5, y, String.format("Vel: dx=%.3f, dy=%.3f, z=%.3f, speed=%.3f", vel.x, vel.y, vel.z, vel.length()));
|
||||
y += 12;
|
||||
var view = client.getMyPlayer().getOrientation();
|
||||
nvgText(vgId, 5, y, String.format("View: horizontal=%.3f, vertical=%.3f", Math.toDegrees(view.x), Math.toDegrees(view.y)));
|
||||
|
|
|
@ -48,7 +48,7 @@ public final class Net {
|
|||
serializer.registerType(19, BlockColorMessage.class);
|
||||
serializer.registerType(20, ChatMessage.class);
|
||||
serializer.registerType(21, ChatWrittenMessage.class);
|
||||
serializer.registerType(22, ClientOrientationUpdateMessage.class);
|
||||
serializer.registerType(22, ClientRecoilMessage.class);
|
||||
}
|
||||
|
||||
public static ExtendedDataInputStream getInputStream(InputStream in) {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package nl.andrewl.aos_core.net.client;
|
||||
|
||||
import nl.andrewl.aos_core.model.Player;
|
||||
import nl.andrewl.record_net.Message;
|
||||
|
||||
/**
|
||||
|
@ -11,4 +12,8 @@ import nl.andrewl.record_net.Message;
|
|||
public record ClientOrientationState(
|
||||
int clientId,
|
||||
float x, float y
|
||||
) implements Message {}
|
||||
) implements Message {
|
||||
public static ClientOrientationState fromPlayer(Player player) {
|
||||
return new ClientOrientationState(player.getId(), player.getOrientation().x, player.getOrientation().y);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,8 +4,8 @@ import nl.andrewl.record_net.Message;
|
|||
|
||||
/**
|
||||
* A message that the server sends to clients, to tell them to update their
|
||||
* player's orientation to the specified values.
|
||||
* player's orientation according to a recoil event.
|
||||
*/
|
||||
public record ClientOrientationUpdateMessage(
|
||||
float x, float y
|
||||
public record ClientRecoilMessage(
|
||||
float dx, float dy
|
||||
) implements Message {}
|
|
@ -39,7 +39,7 @@ public class PlayersCommand {
|
|||
}
|
||||
}
|
||||
|
||||
@CommandLine.Command(name = "list", description = "Kicks a player from the server.")
|
||||
@CommandLine.Command(name = "kick", description = "Kicks a player from the server.")
|
||||
public void kick(
|
||||
@CommandLine.Parameters(paramLabel = "player", description = "The id or name of the player to kick.") String playerIdent
|
||||
) {
|
||||
|
|
|
@ -114,12 +114,7 @@ public class PlayerActionManager {
|
|||
// Apply recoil!
|
||||
float recoilFactor = 10f; // Maximum number of degrees to recoil.
|
||||
float recoil = recoilFactor * gun.getRecoil() + (float) ThreadLocalRandom.current().nextGaussian(0, 0.01);
|
||||
player.getOrientation().y += Math.toRadians(recoil);
|
||||
server.getPlayerManager().getHandler(player.getId()).sendDatagramPacket(new ClientOrientationUpdateMessage(
|
||||
player.getOrientation().x(),
|
||||
player.getOrientation().y()
|
||||
));
|
||||
server.getPlayerManager().broadcastUdpMessageToAllBut(player.getUpdateMessage(now), player);
|
||||
server.getPlayerManager().getHandler(player.getId()).sendDatagramPacket(new ClientRecoilMessage(0, Math.toRadians(recoil)));
|
||||
// Play sound!
|
||||
String shotSound = null;
|
||||
if (gun instanceof Rifle) {
|
||||
|
|
Loading…
Reference in New Issue