issue with Cube Positioning in Multiplayer Game (Three.js and PHP)

Issue with Cube Positioning in Three.js and PHP Multiplayer Game

I’m developing a multiplayer game where players control cubes (representing themselves) in a 3D environment rendered using Three.js. The game backend is handled with PHP and MySQL for storing game data, including cube positions. Each player’s cube should move independently based on their input, but I’m encountering an issue where the red cube’s position seems to mirror the green cube’s position in the database after movements.

Problem Description:

  • Red Cube Issue: When either player moves their cube, the red cube’s position in the database updates to match the green cube’s position instead of maintaining its own independent position. This results in both cubes appearing in the same location in the game world after movements.

  • Green Cube Functionality: The green cube behaves correctly, moving independently and updating its position accurately in the database.

Code Overview:

  • PHP (game.php): Handles updates to cube positions based on player input and stores them in a MySQL database. Here’s an example of how positions are updated:

    php
    

    Copy code

    // Example of how positions are updated in game.php if ($_SESSION['username'] == $_POST['player']) { $query = "UPDATE fight SET player1_position_x=?, player1_position_y=?, player1_position_z=? WHERE id=?"; } else { $query = "UPDATE fight SET player2_position_x=?, player2_position_y=?, player2_position_z=? WHERE id=?"; }

  • JavaScript (Three.js): Controls cube movements on the client-side and sends AJAX requests to update and fetch cube positions. Here’s an example of how positions are updated:

    javascript
    

    Copy code

    // Example of how positions are updated in JavaScript function updateCubePosition(x, y, z, player) { const xhr = new XMLHttpRequest(); xhr.open('POST', 'game.php?fight_id=<?php echo $fightId; ?>', true); // ... }

What I’ve Tried:

  • Ensured that AJAX requests correctly send and receive cube positions.

  • Verified that PHP scripts handle updates based on the correct player identity ($_SESSION['username'] vs. $_POST['player']).

  • Confirmed that the JavaScript handles cube movements and updates positions accurately on the client-side.

Request for Assistance:

I’m seeking guidance on why the red cube’s position in the database does not update independently and instead mirrors the green cube’s position after movements. How can I ensure each cube (player) maintains its own position without interference?

Any insights or suggestions on debugging or fixing this issue would be greatly appreciated. Thank you for your help!=

when opened the game i could move green perfect and update the position on db different browser i can make the green move but when i i try to move the green in the separate browser the red becomes green or it moves but doesnt save positions or green follows red and becomes green very confusing

New contributor

John is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật