generated from Persson-dev/Godot-Xmake
fix position sync issues
All checks were successful
Linux arm64 / Build (pull_request) Successful in 1m31s
All checks were successful
Linux arm64 / Build (pull_request) Successful in 1m31s
This commit is contained in:
@@ -64,14 +64,6 @@ void World::HandlePacket(const protocol::packets::PlayerLeave& a_PlayerLeave) {
|
||||
RemovePlayer(a_PlayerLeave.m_Data.m_PlayerId);
|
||||
}
|
||||
|
||||
void World::HandlePacket(const protocol::packets::PlayerPositionAndRotation& a_PlayerPos) {
|
||||
const auto& data = a_PlayerPos.m_Data;
|
||||
if (data.m_Player == get_multiplayer()->get_unique_id() || data.m_Player != a_PlayerPos.m_Sender)
|
||||
return;
|
||||
|
||||
SetPlayerPositionAndRotation(data.m_Player, data.m_Position, data.m_Rotation, data.m_Velocity);
|
||||
}
|
||||
|
||||
void World::AddPlayer(PlayerID a_PlayerId, String a_PlayerName) {
|
||||
UtilityFunctions::print("New Player with id : ", a_PlayerId, " and name ", a_PlayerName);
|
||||
if (a_PlayerId == get_multiplayer()->get_unique_id()) {
|
||||
|
||||
@@ -14,7 +14,8 @@ void packets::ConcretePacket<PT, Data>::Accept(PacketVisitor& a_Visitor) const {
|
||||
a_Visitor.Visit(*this);
|
||||
}
|
||||
|
||||
#define DeclarePacket(PacketName, packetSendType, packetSenderType) static_assert(static_cast<unsigned>(PacketSendType::packetSendType) && static_cast<unsigned>(PacketSenderType::packetSenderType));
|
||||
#define DeclarePacket(PacketName, packetSendType, packetSenderType) \
|
||||
static_assert(static_cast<unsigned>(PacketSendType::packetSendType) && static_cast<unsigned>(PacketSenderType::packetSenderType));
|
||||
|
||||
DeclareAllPacket()
|
||||
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
#include <godot_cpp/classes/engine.hpp>
|
||||
#include <godot_cpp/classes/multiplayer_api.hpp>
|
||||
|
||||
#include <godot_cpp/variant/utility_functions.hpp>
|
||||
|
||||
namespace blitz {
|
||||
|
||||
using namespace godot;
|
||||
@@ -20,10 +22,12 @@ void ClientWorld::_process(float delta) {
|
||||
if (Engine::get_singleton()->is_editor_hint())
|
||||
return;
|
||||
#endif
|
||||
|
||||
m_PassedTime += delta;
|
||||
if (m_PassedTime < 0.05f)
|
||||
return;
|
||||
|
||||
m_PassedTime = 0.0f;
|
||||
|
||||
UpdatePlayerPos();
|
||||
}
|
||||
@@ -36,4 +40,18 @@ void ClientWorld::UpdatePlayerPos() {
|
||||
}
|
||||
}
|
||||
|
||||
void ClientWorld::HandlePacket(const protocol::packets::PlayerPositionAndRotation& a_PlayerPos) {
|
||||
const auto& data = a_PlayerPos.m_Data;
|
||||
if (data.m_Player == get_multiplayer()->get_unique_id()) {
|
||||
Player* player = GetPlayerById(get_multiplayer()->get_unique_id());
|
||||
if (player && (a_PlayerPos.m_Data.m_Position - player->get_position()).length() > 10) {
|
||||
SetPlayerPositionAndRotation(data.m_Player, data.m_Position, data.m_Rotation, data.m_Velocity);
|
||||
godot::UtilityFunctions::print("Teleported to : ", data.m_Position);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
SetPlayerPositionAndRotation(data.m_Player, data.m_Position, data.m_Rotation, data.m_Velocity);
|
||||
}
|
||||
|
||||
} // namespace blitz
|
||||
@@ -39,7 +39,7 @@ static const float AnimationBlend = 7.0;
|
||||
|
||||
void FirstPersonPlayer::_bind_methods() {}
|
||||
|
||||
FirstPersonPlayer::FirstPersonPlayer() : m_BobTime(0) {}
|
||||
FirstPersonPlayer::FirstPersonPlayer() : Player(), m_BobTime(0) {}
|
||||
|
||||
FirstPersonPlayer::~FirstPersonPlayer() {}
|
||||
|
||||
@@ -52,6 +52,9 @@ void FirstPersonPlayer::_ready() {
|
||||
m_Camera = Object::cast_to<Camera3D>(m_Head->find_child("Camera"));
|
||||
m_AnimationTree = Object::cast_to<AnimationTree>(find_child("AnimationTree"));
|
||||
m_Mesh = Object::cast_to<Node3D>(find_child("Mesh"));
|
||||
|
||||
set_position({0, 0, 0});
|
||||
set_velocity({0, 0, 0});
|
||||
}
|
||||
|
||||
void FirstPersonPlayer::_unhandled_input(const godot::Ref<godot::InputEvent>& a_Event) {
|
||||
@@ -89,9 +92,9 @@ void FirstPersonPlayer::_physics_process(float a_Delta) {
|
||||
UpdateFOV(a_Delta);
|
||||
UpdateBobbing(a_Delta);
|
||||
|
||||
UpdateAnimation(a_Delta);
|
||||
|
||||
move_and_slide();
|
||||
|
||||
UpdateAnimation(a_Delta);
|
||||
}
|
||||
|
||||
void FirstPersonPlayer::UpdateBobbing(float a_Delta) {
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include <godot_cpp/variant/utility_functions.hpp>
|
||||
|
||||
static const float WalkSpeed = 2.0;
|
||||
static const float RunSpeed = 5.0;
|
||||
static const float RunSpeed = 7.0;
|
||||
static const float JumpStrength = 15.0;
|
||||
static const float Gravity = 50.0;
|
||||
|
||||
@@ -20,7 +20,7 @@ using namespace godot;
|
||||
|
||||
void Player::_bind_methods() {}
|
||||
|
||||
Player::Player() {}
|
||||
Player::Player() : m_PeerId(0) {}
|
||||
|
||||
Player::~Player() {}
|
||||
|
||||
@@ -31,7 +31,9 @@ void Player::_ready() {
|
||||
DEV_ASSERT(m_Mesh);
|
||||
DEV_ASSERT(m_AnimationTree);
|
||||
|
||||
apply_floor_snap();
|
||||
set_position({0, 0, 0});
|
||||
set_velocity({0, 0, 0});
|
||||
|
||||
animate(0);
|
||||
}
|
||||
|
||||
@@ -39,6 +41,7 @@ void Player::_physics_process(float delta) {
|
||||
if (godot::Engine::get_singleton()->is_editor_hint())
|
||||
return;
|
||||
|
||||
move_and_slide();
|
||||
animate(delta);
|
||||
}
|
||||
|
||||
@@ -46,8 +49,10 @@ void Player::animate(float delta) {
|
||||
if (is_on_floor()) {
|
||||
m_AnimationTree->set("parameters/ground_air_transition/transition_request", "grounded");
|
||||
|
||||
if (get_velocity().length() > 0) {
|
||||
if (m_Speed == RunSpeed) {
|
||||
float speed = get_velocity().length();
|
||||
|
||||
if (speed > 0.2f) {
|
||||
if (speed >= RunSpeed) {
|
||||
m_AnimationTree->set("parameters/iwr_blend/blend_amount",
|
||||
godot::UtilityFunctions::lerp(
|
||||
m_AnimationTree->get("parameters/iwr_blend/blend_amount"), 1.0, delta * AnimationBlend));
|
||||
|
||||
@@ -23,6 +23,7 @@ void ServerWorld::_process(float delta) {
|
||||
if (m_PassedTime < 0.05f)
|
||||
return;
|
||||
|
||||
m_PassedTime = 0.0f;
|
||||
SyncPlayersPos();
|
||||
}
|
||||
|
||||
@@ -35,4 +36,12 @@ void ServerWorld::SyncPlayersPos() {
|
||||
}
|
||||
}
|
||||
|
||||
void ServerWorld::HandlePacket(const protocol::packets::PlayerPositionAndRotation& a_PlayerPos) {
|
||||
const auto& data = a_PlayerPos.m_Data;
|
||||
if (data.m_Player != a_PlayerPos.m_Sender)
|
||||
return;
|
||||
|
||||
SetPlayerPositionAndRotation(data.m_Player, data.m_Position, data.m_Rotation, data.m_Velocity);
|
||||
}
|
||||
|
||||
} // namespace blitz
|
||||
Reference in New Issue
Block a user