From 15b890ad552870398d9e153c89274b1d8354a922 Mon Sep 17 00:00:00 2001 From: Sara Date: Wed, 11 Jun 2025 23:57:43 +0200 Subject: [PATCH] feat: more work on checkpoints --- modules/going/checkpoint.cpp | 25 +++++++------------------ modules/going/checkpoint.h | 7 +++---- modules/going/player_body.cpp | 9 +++++++++ modules/going/player_body.h | 1 + project/objects/player.tscn | 1 + 5 files changed, 21 insertions(+), 22 deletions(-) diff --git a/modules/going/checkpoint.cpp b/modules/going/checkpoint.cpp index 2a520f89..0454a2a5 100644 --- a/modules/going/checkpoint.cpp +++ b/modules/going/checkpoint.cpp @@ -5,8 +5,7 @@ void Checkpoint::_bind_methods() { BIND_PROPERTY(Variant::VECTOR3, location); - BIND_PROPERTY(Variant::BOOL, can_jump); - BIND_PROPERTY(Variant::BOOL, can_bash); + BIND_PROPERTY(Variant::VECTOR3, camera_location); } void Checkpoint::set_location(Transform3D location) { @@ -17,32 +16,22 @@ Transform3D Checkpoint::get_location() const { return this->location; } -void Checkpoint::set_can_jump(bool can_jump) { - this->can_jump = can_jump; +void Checkpoint::set_camera_location(Transform3D location) { + this->camera_location = location; } -bool Checkpoint::get_can_jump() const { - return this->can_jump; -} - -void Checkpoint::set_can_bash(bool can_bash) { - this->can_bash = can_bash; -} - -bool Checkpoint::get_can_bash() const { - return this->can_bash; +Transform3D Checkpoint::get_camera_location() const { + return this->camera_location; } void Checkpoint::load(PlayerBody *body) const { body->set_global_transform(this->location); - body->set_can_jump(this->can_jump); - // body->set_can_bash(this->can_bash); + body->get_camera()->set_global_transform(this->camera_location); } void Checkpoint::save(PlayerBody *body) { this->set_location(body->get_global_transform_interpolated()); - this->set_can_jump(body->get_can_jump()); - // self->set_can_bash(body->get_can_bash()); + this->set_camera_location(body->get_camera()->get_global_transform_interpolated()); } Ref Checkpoint::save_new(PlayerBody *body) { diff --git a/modules/going/checkpoint.h b/modules/going/checkpoint.h index 53afddd9..5ffc58fa 100644 --- a/modules/going/checkpoint.h +++ b/modules/going/checkpoint.h @@ -13,16 +13,15 @@ class Checkpoint : public Resource { public: void set_location(Transform3D location); Transform3D get_location() const; - void set_can_jump(bool can_jump); - bool get_can_jump() const; - void set_can_bash(bool can_bash); - bool get_can_bash() const; + void set_camera_location(Transform3D camera_location); + Transform3D get_camera_location() const; void load(PlayerBody *body) const; void save(PlayerBody *body); static Ref save_new(PlayerBody *body); private: Transform3D location{}; + Transform3D camera_location{}; bool can_jump{false}, can_bash{false}; }; diff --git a/modules/going/player_body.cpp b/modules/going/player_body.cpp index 8dca37ab..6c984563 100644 --- a/modules/going/player_body.cpp +++ b/modules/going/player_body.cpp @@ -46,6 +46,9 @@ void PlayerBody::_notification(int what) { case NOTIFICATION_ENTER_TREE: this->enter_tree(); return; + case NOTIFICATION_READY: + this->ready(); + return; case NOTIFICATION_PROCESS: this->process(this->get_process_delta_time()); return; @@ -61,6 +64,10 @@ void PlayerBody::enter_tree() { this->model = Object::cast_to(this->get_node(NodePath("character"))); this->anim = Object::cast_to(this->get_node(NodePath("character/AnimationPlayer"))); this->camera = Object::cast_to(this->get_node(NodePath("Camera3D"))); + this->state = Object::cast_to(this->get_node(NodePath("%PlayerStateMachine"))); +} + +void PlayerBody::ready() { this->camera->set_fov(this->min_fov); this->last_checkpoint = Checkpoint::save_new(this); } @@ -85,6 +92,8 @@ void PlayerBody::save_checkpoint() { void PlayerBody::load_checkpoint() { this->last_checkpoint->load(this); + this->force_update_transform(); + this->set_velocity(Vector3{}); this->state->force_state(); } diff --git a/modules/going/player_body.h b/modules/going/player_body.h index 35426ef6..c3b7016c 100644 --- a/modules/going/player_body.h +++ b/modules/going/player_body.h @@ -12,6 +12,7 @@ class PlayerBody : public CharacterBody3D { static void _bind_methods(); void _notification(int what); void enter_tree(); + void ready(); void process(double delta); void physics_process(double delta); diff --git a/project/objects/player.tscn b/project/objects/player.tscn index 71efd7f4..1c9f7104 100644 --- a/project/objects/player.tscn +++ b/project/objects/player.tscn @@ -36,6 +36,7 @@ target_speed = 25.0 jump_impulse = Vector2(0.9, 5) [node name="PlayerStateMachine" type="PlayerStateMachine" parent="."] +unique_name_in_owner = true [node name="CollisionShape3D" type="CollisionShape3D" parent="."] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.05124, 0)