fix shooting
This commit is contained in:
parent
e8fb14b809
commit
50232c0816
@ -120,9 +120,11 @@ class Session : public std::enable_shared_from_this<Session> {
|
||||
std::cout << "Player " << id_ << " fired " << shotCount << " shots → broadcasting\n";
|
||||
|
||||
for (auto& session : g_sessions) {
|
||||
if (session->get_id() != id_) {
|
||||
session->send_message(broadcast);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
std::cerr << "Unknown message type: " << type << "\n";
|
||||
}
|
||||
|
||||
25
src/Game.cpp
25
src/Game.cpp
@ -233,6 +233,8 @@ namespace ZL
|
||||
if (now - lastProjectileFireTime >= static_cast<uint64_t>(projectileCooldownMs)) {
|
||||
lastProjectileFireTime = now;
|
||||
|
||||
this->fireProjectiles();
|
||||
|
||||
Eigen::Vector3f localForward = { 0, 0, -1 };
|
||||
Eigen::Vector3f worldForward = (Environment::shipState.rotation * localForward).normalized();
|
||||
|
||||
@ -1130,15 +1132,29 @@ namespace ZL
|
||||
const float lifeMs = 5000.0f;
|
||||
const float size = 0.5f;
|
||||
|
||||
auto remotePlayersSnapshot = networkClient->getRemotePlayers();
|
||||
for (const auto& pi : pending) {
|
||||
Eigen::Vector3f dir = pi.direction;
|
||||
float len = dir.norm();
|
||||
if (len <= 1e-6f) continue;
|
||||
dir /= len;
|
||||
Eigen::Vector3f baseVel = dir * projectileSpeed;
|
||||
|
||||
int shotCount = 1;
|
||||
shotCount = 2;
|
||||
Eigen::Matrix3f shooterRot = Eigen::Matrix3f::Identity();
|
||||
float shooterVel = 0.0f;
|
||||
auto it = remotePlayersSnapshot.find(pi.shooterId);
|
||||
if (it != remotePlayersSnapshot.end()) {
|
||||
std::chrono::system_clock::time_point pktTime{ std::chrono::milliseconds(pi.clientTime) };
|
||||
if (it->second.canFetchClientStateAtTime(pktTime)) {
|
||||
ClientState shooterState = it->second.fetchClientStateAtTime(pktTime);
|
||||
shooterRot = shooterState.rotation;
|
||||
shooterVel = shooterState.velocity;
|
||||
}
|
||||
}
|
||||
|
||||
float speedWithOwner = projectileSpeed + shooterVel;
|
||||
Eigen::Vector3f baseVel = dir * speedWithOwner;
|
||||
|
||||
int shotCount = 2;
|
||||
|
||||
std::vector<Eigen::Vector3f> localOffsets = {
|
||||
{-1.5f, 0.9f, 5.0f},
|
||||
@ -1146,7 +1162,8 @@ namespace ZL
|
||||
};
|
||||
|
||||
for (int i = 0; i < shotCount; ++i) {
|
||||
Eigen::Vector3f shotPos = pi.position + localOffsets[i];
|
||||
Eigen::Vector3f rotatedOffset = shooterRot * localOffsets[i];
|
||||
Eigen::Vector3f shotPos = pi.position + rotatedOffset;
|
||||
|
||||
for (auto& p : projectiles) {
|
||||
if (!p->isActive()) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user