Compare commits

6 Commits

Author SHA1 Message Date
89b62317d4 brodacast shoot 2024-08-27 16:21:42 +02:00
2353cbb2be make factories 2024-08-27 15:42:23 +02:00
3c6a3dba44 refactor player 2024-08-27 15:29:45 +02:00
0d72e7f765 set bullet transform 2024-08-27 15:01:32 +02:00
60d0a83345 bullet: remove transparency 2024-08-27 15:01:14 +02:00
e5436241ef attach pencil case to right arm 2024-08-26 12:23:40 +02:00
16 changed files with 202 additions and 139 deletions

View File

@@ -314,12 +314,13 @@ states/Start/position = Vector2(107.334, 120.683)
transitions = ["Start", "Movement", SubResource("AnimationNodeStateMachineTransition_d2yto"), "JumpBlend", "Movement", SubResource("AnimationNodeStateMachineTransition_04hs0"), "Movement", "JumpBlend", SubResource("AnimationNodeStateMachineTransition_a4m5g")]
graph_offset = Vector2(18, 52)
[node name="Player" type="CharacterBody3D"]
[node name="Player" type="Player"]
collision_layer = 2
collision_mask = 3
[node name="Head" type="Node3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.55647, 0)
visible = false
[node name="FPV" parent="Head" instance=ExtResource("9_0cwor")]
transform = Transform3D(-1, 0, -1.50996e-07, 0, 1, 0, 1.50996e-07, 0, -1, 0, -1.55647, 0)
@@ -834,12 +835,12 @@ mesh = ExtResource("7_skjds")
skin = SubResource("Skin_unkc0")
[node name="Hand" type="BoneAttachment3D" parent="Armature/Skeleton3D"]
transform = Transform3D(-0.754949, -0.655201, -0.0276231, -0.655704, 0.753531, 0.0473583, -0.0102144, 0.0538656, -0.998496, -7.36985, 102.466, -285.249)
bone_name = "mixamorig_LeftHand"
bone_idx = 12
transform = Transform3D(-0.101809, 0.0274908, 0.994424, -0.100283, 0.994242, -0.0377525, -0.989736, -0.103568, -0.0984655, -33.2805, 32.3409, -274.352)
bone_name = "mixamorig_RightHand"
bone_idx = 36
[node name="Pencil Case" type="MeshInstance3D" parent="Armature/Skeleton3D/Hand"]
transform = Transform3D(57.2088, -233.054, -180.036, 5.64897, 184.237, -236.696, 294.441, 41.7466, 39.5215, 23.2506, -3.13713, 16.4251)
transform = Transform3D(9.99555, 15.6762, -299.423, -7.80417, 299.502, 15.4192, 299.732, 7.27518, 10.3868, 14.9476, 66.4479, 12.5163)
mesh = SubResource("CylinderMesh_spot0")
skeleton = NodePath("../..")

View File

@@ -0,0 +1,11 @@
#pragma once
#include <client/Player.h>
namespace blitz {
namespace PlayerFactory {
Player* CreateStudent();
} // namespace PlayerFactory
} // namespace blitz

View File

@@ -0,0 +1,11 @@
#pragma once
#include <client/Bullet.h>
namespace blitz {
namespace ProjectileFactory {
Bullet* CreatePen();
} // namespace ProjectileFactory
} // namespace blitz

View File

@@ -25,13 +25,15 @@ class World : public godot::Node3D, public protocol::PacketHandler {
void HandlePacket(const protocol::packets::PlayerJoin&) override;
void HandlePacket(const protocol::packets::PlayerLeave&) override;
void HandlePacket(const protocol::packets::PlayerShoot&) override;
protected:
NetworkInterface* m_NetworkInterface;
godot::Node* m_Players;
float m_PassedTime;
virtual void AddProjectile(
PlayerID a_Shooter, const godot::Vector3& a_Position, const godot::Vector3& a_Rotation, const godot::Vector3& a_Velocity);
virtual void AddPlayer(PlayerID a_PlayerId, godot::String a_PlayerName);
virtual void RemovePlayer(PlayerID a_PlayerId);
virtual void SetPlayerPositionAndRotation(

View File

@@ -1,9 +1,9 @@
#pragma once
#include <blitz/common/Types.h>
#include <vector>
#include <godot_cpp/variant/string.hpp>
#include <godot_cpp/variant/vector3.hpp>
#include <vector>
namespace blitz {
namespace protocol {
@@ -66,7 +66,12 @@ struct PlayerPositionAndRotation {
godot::Vector3 m_Velocity;
};
struct PlayerShoot {};
struct PlayerShoot {
PlayerID m_Sender;
godot::Vector3 m_Position;
godot::Vector3 m_Rotation;
godot::Vector3 m_Velocity;
};
} // namespace data
} // namespace protocol

View File

@@ -18,9 +18,8 @@ class Bullet : public godot::Node3D {
private:
bool m_Stuck;
float m_LifeTime;
void SetTransparency(godot::Node* a_Root, float a_Transparency);
void Destroy();
};
} // namespace blitz

View File

@@ -1,17 +1,18 @@
#pragma once
#include <blitz/common/Types.h>
#include <godot_cpp/classes/animation_tree.hpp>
#include <godot_cpp/classes/character_body3d.hpp>
#include <godot_cpp/classes/node3d.hpp>
#include <blitz/common/Types.h>
namespace blitz {
class World;
class PlayerController;
class Player : public godot::Node {
class Player : public godot::CharacterBody3D {
GDCLASS(Player, godot::Node);
GDCLASS(Player, godot::CharacterBody3D);
protected:
static void _bind_methods();
@@ -39,9 +40,7 @@ class Player : public godot::Node {
protected:
godot::Node3D* m_Mesh;
godot::Node3D* m_Head;
godot::AnimationTree* m_AnimationTree;
godot::CharacterBody3D* m_Player;
godot::Vector3 m_SnapVector;
PeerID m_PeerId;
@@ -51,5 +50,6 @@ class Player : public godot::Node {
void BlendAnimation(const godot::String& a_AnimationName, float a_Goal, float a_Delta);
friend class World;
friend class PlayerController;
};
} // namespace blitz

View File

@@ -5,29 +5,34 @@
namespace blitz {
class FirstPersonPlayer : public Player {
GDCLASS(FirstPersonPlayer, godot::Node)
class NetworkInterface;
class PlayerController : public godot::Node {
GDCLASS(PlayerController, godot::Node)
protected:
static void _bind_methods();
public:
FirstPersonPlayer();
~FirstPersonPlayer();
PlayerController();
~PlayerController();
// Godot overrides
void _unhandled_input(const godot::Ref<godot::InputEvent>&);
void _physics_process(float delta) override;
void _process(float delta);
void _ready();
private:
godot::Camera3D* m_Camera;
float m_BobTime;
float m_Speed;
Player* m_Player;
godot::Node3D* m_Head;
NetworkInterface* m_NetworkInterface;
void UpdateBobbing(float delta);
void UpdateFOV(float delta);
void UpdateCamera(const godot::InputEventMouseMotion&);
void UpdatePosition(float delta);
void UpdateVelocity(float delta);
void Shoot();
};

View File

@@ -0,0 +1,17 @@
#include <blitz/factory/PlayerFactory.h>
#include <godot_cpp/classes/packed_scene.hpp>
#include <godot_cpp/classes/resource_loader.hpp>
namespace blitz {
namespace PlayerFactory {
using namespace godot;
Player* CreateStudent() {
Ref<PackedScene> scene = ResourceLoader::get_singleton()->load("res://Scenes/Characters/remy.tscn");
return Object::cast_to<Player>(scene->instantiate());
}
} // namespace PlayerFactory
} // namespace blitz

View File

@@ -0,0 +1,17 @@
#include <blitz/factory/ProjectileFactory.h>
#include <godot_cpp/classes/packed_scene.hpp>
#include <godot_cpp/classes/resource_loader.hpp>
namespace blitz {
namespace ProjectileFactory {
using namespace godot;
Bullet* CreatePen() {
Ref<PackedScene> bulletScene = ResourceLoader::get_singleton()->load("res://Scenes/Weapons/pen.tscn");
return Object::cast_to<Bullet>(bulletScene->instantiate());
}
} // namespace ProjectileFactory
} // namespace blitz

View File

@@ -1,12 +1,12 @@
#include <blitz/godot/World.h>
#include <blitz/factory/PlayerFactory.h>
#include <blitz/factory/ProjectileFactory.h>
#include <blitz/godot/NetworkInterface.h>
#include <client/FirstPersonPlayer.h>
#include <client/Player.h>
#include <client/PlayerController.h>
#include <godot_cpp/classes/engine.hpp>
#include <godot_cpp/classes/multiplayer_api.hpp>
#include <godot_cpp/classes/packed_scene.hpp>
#include <godot_cpp/classes/resource_loader.hpp>
#include <godot_cpp/variant/utility_functions.hpp>
@@ -14,8 +14,6 @@ using namespace godot;
namespace blitz {
static const char PlayerScenePath[] = "res://Scenes/Characters/remy.tscn";
void World::_bind_methods() {}
void World::_ready() {
@@ -31,6 +29,7 @@ void World::_ready() {
m_NetworkInterface->RegisterHandler(protocol::PacketType::PlayerJoin, *this);
m_NetworkInterface->RegisterHandler(protocol::PacketType::PlayerLeave, *this);
m_NetworkInterface->RegisterHandler(protocol::PacketType::PlayerPositionAndRotation, *this);
m_NetworkInterface->RegisterHandler(protocol::PacketType::PlayerShoot, *this);
}
@@ -63,30 +62,23 @@ void World::HandlePacket(const protocol::packets::PlayerLeave& a_PlayerLeave) {
RemovePlayer(a_PlayerLeave.m_Data.m_PlayerId);
}
void World::HandlePacket(const protocol::packets::PlayerShoot& a_PlayerShoot) {
const protocol::data::PlayerShoot& playerShoot = a_PlayerShoot.m_Data;
AddProjectile(playerShoot.m_Sender, playerShoot.m_Position, playerShoot.m_Rotation, playerShoot.m_Velocity);
}
void World::AddPlayer(PlayerID a_PlayerId, String a_PlayerName) {
UtilityFunctions::print("New Player with id : ", a_PlayerId, " and name ", a_PlayerName);
Player* player = PlayerFactory::CreateStudent();
player->set_name(UtilityFunctions::var_to_str(a_PlayerId));
player->m_PeerId = a_PlayerId;
m_Players->add_child(player);
if (a_PlayerId == get_multiplayer()->get_unique_id()) {
Ref<PackedScene> serverScene = ResourceLoader::get_singleton()->load(PlayerScenePath);
Node* playerContent = serverScene->instantiate();
FirstPersonPlayer* player = memnew(FirstPersonPlayer);
player->set_name(UtilityFunctions::var_to_str(a_PlayerId));
player->m_PeerId = a_PlayerId;
player->add_child(playerContent);
m_Players->add_child(player);
} else {
Ref<PackedScene> serverScene = ResourceLoader::get_singleton()->load(PlayerScenePath);
Node* playerContent = serverScene->instantiate();
Player* player = memnew(Player);
player->set_name(UtilityFunctions::var_to_str(a_PlayerId));
player->m_PeerId = a_PlayerId;
player->add_child(playerContent);
m_Players->add_child(player);
PlayerController* playerController = memnew(PlayerController);
player->add_child(playerController);
}
}
@@ -108,4 +100,22 @@ void World::SetPlayerPositionAndRotation(
}
}
void World::AddProjectile(
PlayerID a_Shooter, const godot::Vector3& a_Position, const godot::Vector3& a_Rotation, const godot::Vector3& a_Velocity) {
Player* shooter = GetPlayerById(a_Shooter);
if (!shooter)
return;
Bullet* bullet = ProjectileFactory::CreatePen();
bullet->set_position(a_Position);
Transform3D bulletTransform = bullet->get_transform();
bulletTransform.basis.set_euler(a_Rotation);
bullet->set_transform(bulletTransform);
Node* entities = get_node<Node>("WorldContent/Entities");
entities->add_child(bullet);
}
} // namespace blitz

View File

@@ -272,9 +272,13 @@ void Deserializer::DeserializePacketData(data::PlayerPositionAndRotation& a_Pack
void Serializer::SerializePacketData(const data::PlayerShoot& a_Packet) {}
void Serializer::SerializePacketData(const data::PlayerShoot& a_Packet) {
m_Buffer << a_Packet.m_Sender << a_Packet.m_Position << a_Packet.m_Rotation << a_Packet.m_Velocity;
}
void Deserializer::DeserializePacketData(data::PlayerShoot& a_Packet) {}
void Deserializer::DeserializePacketData(data::PlayerShoot& a_Packet) {
m_Buffer >> a_Packet.m_Sender >> a_Packet.m_Position >> a_Packet.m_Rotation >> a_Packet.m_Velocity;
}

View File

@@ -4,6 +4,7 @@
#include <godot_cpp/classes/geometry_instance3d.hpp>
#include <godot_cpp/classes/physics_direct_space_state3d.hpp>
#include <godot_cpp/classes/physics_ray_query_parameters3d.hpp>
#include <godot_cpp/classes/timer.hpp>
#include <godot_cpp/classes/world3d.hpp>
#include <godot_cpp/variant/utility_functions.hpp>
@@ -18,7 +19,13 @@ void Bullet::_bind_methods() {}
Bullet::Bullet() : m_Stuck(false) {}
void Bullet::_ready() {}
void Bullet::_ready() {
Timer* timer = memnew(Timer);
add_child(timer);
timer->connect("timeout", callable_mp(this, &Bullet::Destroy));
timer->set_wait_time(MaxAlive);
timer->start();
}
Bullet::~Bullet() {}
@@ -27,14 +34,7 @@ void Bullet::_process(float a_Delta) {
return;
}
m_LifeTime += a_Delta;
if (m_LifeTime > MaxAlive) {
queue_free();
return;
}
auto* head = get_node<Node3D>("Armature");
SetTransparency(head, m_LifeTime / MaxAlive);
if (m_Stuck)
return;
@@ -56,15 +56,8 @@ void Bullet::_process(float a_Delta) {
head->set_global_position(intersectPoint);
}
void Bullet::SetTransparency(Node* a_Root, float a_Transparency) {
for (int i = 0; i < a_Root->get_child_count(); i++) {
SetTransparency(a_Root->get_child(i), a_Transparency);
}
GeometryInstance3D* mesh = Object::cast_to<GeometryInstance3D>(a_Root);
if (mesh) {
mesh->set_transparency(a_Transparency);
}
void Bullet::Destroy() {
queue_free();
}
} // namespace blitz

View File

@@ -31,19 +31,13 @@ void Player::_ready() {
return;
}
m_Player = get_node<CharacterBody3D>("Player");
DEV_ASSERT(m_Player);
// we set the player to an invalid position
m_Player->set_position({-99999, -999999, -999999});
set_position({-99999, -999999, -999999});
m_Head = get_node<Node3D>("Player/Head");
DEV_ASSERT(m_Head);
m_Mesh = get_node<Node3D>("Player/Armature");
m_Mesh = get_node<Node3D>("Armature");
DEV_ASSERT(m_Mesh);
m_AnimationTree = get_node<AnimationTree>("Player/AnimationTree");
m_AnimationTree = get_node<AnimationTree>("AnimationTree");
DEV_ASSERT(m_AnimationTree);
}
@@ -51,29 +45,29 @@ void Player::_physics_process(float delta) {
if (godot::Engine::get_singleton()->is_editor_hint())
return;
m_Player->move_and_slide();
move_and_slide();
UpdateAnimation(delta);
}
Vector3 Player::GetPosition() const {
return m_Player->get_position();
return get_position();
}
void Player::SetPosition(const Vector3& a_Position) {
m_Player->set_position(a_Position);
set_position(a_Position);
}
Vector3 Player::GetVelocity() const {
return m_Player->get_velocity();
return get_velocity();
}
void Player::SetVelocity(const Vector3& a_Velocity) {
m_Player->set_velocity(a_Velocity);
set_velocity(a_Velocity);
}
void Player::UpdateAnimation(float a_Delta) {
Vector3 velocity = m_Player->get_velocity();
float angle = m_Player->get_rotation().y;
Vector3 velocity = get_velocity();
float angle = get_rotation().y;
Vector3 direction = velocity.rotated({0, 1, 0}, -angle);
if (direction.length() < 1.0f) {
@@ -91,8 +85,8 @@ void Player::UpdateAnimation(float a_Delta) {
float ratio = 0.5f - (UtilityFunctions::absf(direction.z) - UtilityFunctions::absf(direction.x)) * 0.5f;
BlendAnimation("parameters/Movement/Walking/blend_amount", ratio, a_Delta);
m_AnimationTree->set("parameters/conditions/jump", !m_Player->is_on_floor() && m_Player->get_velocity().y > 0.0f);
m_AnimationTree->set("parameters/conditions/is_on_floor", m_Player->is_on_floor());
m_AnimationTree->set("parameters/conditions/jump", !is_on_floor() && get_velocity().y > 0.0f);
m_AnimationTree->set("parameters/conditions/is_on_floor", is_on_floor());
}
void Player::BlendAnimation(const godot::String& a_AnimationName, float a_Goal, float a_Delta) {
@@ -117,11 +111,11 @@ void Player::SetModelVisible(bool a_Visible) {
}
Vector3 Player::GetCameraRotation() const {
return m_Player->get_rotation();
return get_rotation();
}
void Player::SetCameraRotation(const Vector3& a_Rotation) {
m_Player->set_rotation(a_Rotation);
set_rotation(a_Rotation);
}
} // namespace blitz

View File

@@ -1,12 +1,12 @@
#include <client/FirstPersonPlayer.h>
#include <client/PlayerController.h>
#include <blitz/factory/ProjectileFactory.h>
#include <blitz/godot/NetworkInterface.h>
#include <godot_cpp/classes/camera3d.hpp>
#include <godot_cpp/classes/engine.hpp>
#include <godot_cpp/classes/input.hpp>
#include <godot_cpp/classes/input_event_mouse_motion.hpp>
#include <godot_cpp/classes/input_map.hpp>
#include <godot_cpp/classes/packed_scene.hpp>
#include <godot_cpp/classes/resource_loader.hpp>
#include <godot_cpp/core/math.hpp>
#include <godot_cpp/variant/utility_functions.hpp>
@@ -39,17 +39,13 @@ static constexpr float MAX_FOV_VELOCITY = SPRINT_SPEED * 2.0f;
static const float LerpValue = 0.10;
static const float AnimationBlend = 7.0;
static const char BulletScenePath[] = "res://Scenes/Weapons/pen.tscn";
void PlayerController::_bind_methods() {}
void FirstPersonPlayer::_bind_methods() {}
PlayerController::PlayerController() : m_BobTime(0) {}
FirstPersonPlayer::FirstPersonPlayer() : Player(), m_BobTime(0) {}
FirstPersonPlayer::~FirstPersonPlayer() {}
void FirstPersonPlayer::_ready() {
Player::_ready();
PlayerController::~PlayerController() {}
void PlayerController::_ready() {
InputMap::get_singleton()->load_from_project_settings();
if (!Engine::get_singleton()->is_editor_hint()) {
Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_CAPTURED);
@@ -57,18 +53,28 @@ void FirstPersonPlayer::_ready() {
return;
}
m_Player = Object::cast_to<Player>(get_parent());
m_Head = m_Player->get_node<Node3D>("Head");
DEV_ASSERT(m_Head);
m_Head->set_visible(true);
m_Camera = memnew(Camera3D);
m_Camera->set_name("FirstPersonCamera");
m_Head->add_child(m_Camera);
m_Camera->make_current();
SetModelVisible(false);
m_Player->SetModelVisible(false);
SetPosition({0, 100, 0});
SetVelocity({0, 0, 0});
m_Player->SetPosition({0, 1, 0});
m_Player->SetVelocity({0, 0, 0});
m_NetworkInterface = m_Player->get_node<NetworkInterface>("../../../../Network");
DEV_ASSERT(m_NetworkInterface);
}
void FirstPersonPlayer::_unhandled_input(const godot::Ref<godot::InputEvent>& a_Event) {
void PlayerController::_unhandled_input(const godot::Ref<godot::InputEvent>& a_Event) {
auto* event = Object::cast_to<InputEventMouseMotion>(a_Event.ptr());
if (event)
UpdateCamera(*event);
@@ -81,7 +87,7 @@ void FirstPersonPlayer::_unhandled_input(const godot::Ref<godot::InputEvent>& a_
}
}
void FirstPersonPlayer::_physics_process(float a_Delta) {
void PlayerController::_process(float a_Delta) {
#if DEBUG_ENABLED
if (Engine::get_singleton()->is_editor_hint()) {
return;
@@ -91,43 +97,31 @@ void FirstPersonPlayer::_physics_process(float a_Delta) {
auto* Input = Input::get_singleton();
if (!m_Player->is_on_floor())
SetVelocity(GetVelocity() - Vector3{0, GRAVITY * a_Delta, 0});
m_Player->SetVelocity(m_Player->GetVelocity() - Vector3{0, GRAVITY * a_Delta, 0});
if (Input->is_action_pressed("jump") && m_Player->is_on_floor())
SetVelocity({GetVelocity().x, JUMP_VELOCITY, GetVelocity().z});
m_Player->SetVelocity({m_Player->GetVelocity().x, JUMP_VELOCITY, m_Player->GetVelocity().z});
m_Speed = Input->is_action_pressed("sprint") ? SPRINT_SPEED : WALK_SPEED;
UpdatePosition(a_Delta);
UpdateFOV(a_Delta);
UpdateBobbing(a_Delta);
m_Player->move_and_slide();
UpdateAnimation(a_Delta);
UpdateVelocity(a_Delta);
Shoot();
}
void FirstPersonPlayer::Shoot() {
void PlayerController::Shoot() {
if (Input::get_singleton()->is_action_pressed("shoot")) {
Ref<PackedScene> bulletScene = ResourceLoader::get_singleton()->load(BulletScenePath);
auto* bullet = Object::cast_to<Node3D>(bulletScene->instantiate());
bullet->set_position(m_Camera->get_global_position());
Transform3D rotation = bullet->get_transform();
rotation.basis = m_Camera->get_global_transform().basis;
bullet->set_transform(rotation);
Node* entities = get_node<Node>("../../Entities");
entities->add_child(bullet);
// we don't use velocity yet
protocol::packets::PlayerShoot packet(
{m_Player->GetId(), m_Camera->get_global_position(), m_Camera->get_global_transform().basis.get_euler(), {}});
m_NetworkInterface->BroadcastPacket(packet);
}
}
void FirstPersonPlayer::UpdateBobbing(float a_Delta) {
m_BobTime += a_Delta * GetVelocity().length() * m_Player->is_on_floor();
void PlayerController::UpdateBobbing(float a_Delta) {
m_BobTime += a_Delta * m_Player->GetVelocity().length() * m_Player->is_on_floor();
Vector3 newPos{static_cast<float>(Math::cos(m_BobTime * BOB_FREQ / 2.0) * BOB_AMP),
static_cast<float>(Math::sin(m_BobTime * BOB_FREQ) * BOB_AMP), 0};
@@ -135,7 +129,7 @@ void FirstPersonPlayer::UpdateBobbing(float a_Delta) {
// m_Camera->set_transform({m_Camera->get_transform().basis, newPos});
}
void FirstPersonPlayer::UpdateCamera(const InputEventMouseMotion& a_Event) {
void PlayerController::UpdateCamera(const InputEventMouseMotion& a_Event) {
m_Player->rotate_y(-a_Event.get_relative().x * SENSITIVITY);
m_Head->rotate_x(-a_Event.get_relative().y * SENSITIVITY);
@@ -144,7 +138,7 @@ void FirstPersonPlayer::UpdateCamera(const InputEventMouseMotion& a_Event) {
m_Head->set_rotation({rotationX, m_Head->get_rotation().y, m_Head->get_rotation().z});
}
void FirstPersonPlayer::UpdatePosition(float delta) {
void PlayerController::UpdateVelocity(float delta) {
auto* Input = Input::get_singleton();
Vector2 inputDirection = Input->get_vector("move_left", "move_right", "move_forwards", "move_backwards");
@@ -152,25 +146,25 @@ void FirstPersonPlayer::UpdatePosition(float delta) {
if (m_Player->is_on_floor()) {
if (!direction.is_zero_approx()) {
SetVelocity({direction.x * m_Speed, GetVelocity().y, direction.z * m_Speed});
m_Player->SetVelocity({direction.x * m_Speed, m_Player->GetVelocity().y, direction.z * m_Speed});
} else {
SetVelocity({Math::lerp(static_cast<float>(GetVelocity().x), static_cast<float>(direction.x * m_Speed),
static_cast<float>(delta * GROUND_FRICTION)),
GetVelocity().y,
Math::lerp(static_cast<float>(GetVelocity().z), static_cast<float>(direction.z * m_Speed),
m_Player->SetVelocity({Math::lerp(static_cast<float>(m_Player->GetVelocity().x), static_cast<float>(direction.x * m_Speed),
static_cast<float>(delta * GROUND_FRICTION)),
m_Player->GetVelocity().y,
Math::lerp(static_cast<float>(m_Player->GetVelocity().z), static_cast<float>(direction.z * m_Speed),
static_cast<float>(delta * GROUND_FRICTION))});
}
} else {
SetVelocity({Math::lerp(static_cast<float>(GetVelocity().x), static_cast<float>(direction.x * m_Speed),
static_cast<float>(delta * AIR_MOVEMENT)),
GetVelocity().y,
Math::lerp(static_cast<float>(GetVelocity().z), static_cast<float>(direction.z * m_Speed),
m_Player->SetVelocity({Math::lerp(static_cast<float>(m_Player->GetVelocity().x), static_cast<float>(direction.x * m_Speed),
static_cast<float>(delta * AIR_MOVEMENT)),
m_Player->GetVelocity().y,
Math::lerp(static_cast<float>(m_Player->GetVelocity().z), static_cast<float>(direction.z * m_Speed),
static_cast<float>(delta * AIR_MOVEMENT))});
}
}
void FirstPersonPlayer::UpdateFOV(float a_Delta) {
float velocityClamped = Math::clamp(GetVelocity().length(), MIN_FOV_VELOCITY, MAX_FOV_VELOCITY);
void PlayerController::UpdateFOV(float a_Delta) {
float velocityClamped = Math::clamp(m_Player->GetVelocity().length(), MIN_FOV_VELOCITY, MAX_FOV_VELOCITY);
float targetFOV = BASE_FOV + FOV_CHANGE * velocityClamped;
m_Camera->set_fov(Math::lerp(static_cast<float>(m_Camera->get_fov()), targetFOV, a_Delta * FOV_TRANSITION));
}

View File

@@ -1,10 +1,10 @@
#include <blitz/godot/NetworkInterface.h>
#include <client/Bullet.h>
#include <client/ClientWorld.h>
#include <client/FirstPersonPlayer.h>
#include <client/Main.h>
#include <client/MainMenu.h>
#include <client/Player.h>
#include <client/PlayerController.h>
#include <server/Server.h>
#include <server/ServerWorld.h>
@@ -16,7 +16,7 @@ using namespace godot;
static void RegisterClasses() {
GDREGISTER_CLASS(blitz::Player);
GDREGISTER_CLASS(blitz::FirstPersonPlayer);
GDREGISTER_CLASS(blitz::PlayerController);
GDREGISTER_CLASS(blitz::MainMenu);
GDREGISTER_CLASS(blitz::Main);
GDREGISTER_CLASS(blitz::NetworkInterface);