feat: cleanup
This commit is contained in:
parent
3863b622f5
commit
2e4591c3df
|
@ -6,7 +6,6 @@
|
||||||
#include "tunnels_game_mode.hpp"
|
#include "tunnels_game_mode.hpp"
|
||||||
#include "utils/game_root.hpp"
|
#include "utils/game_root.hpp"
|
||||||
#include "utils/godot_macros.h"
|
#include "utils/godot_macros.h"
|
||||||
#include <cmath>
|
|
||||||
#include <godot_cpp/classes/navigation_agent3d.hpp>
|
#include <godot_cpp/classes/navigation_agent3d.hpp>
|
||||||
#include <godot_cpp/classes/time.hpp>
|
#include <godot_cpp/classes/time.hpp>
|
||||||
#include <godot_cpp/variant/callable.hpp>
|
#include <godot_cpp/variant/callable.hpp>
|
||||||
|
@ -63,7 +62,7 @@ void CharacterActor::move(Vector3 world_vector) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void CharacterActor::aim(Vector3 at) {
|
void CharacterActor::aim(Vector3 at) {
|
||||||
// calculate the forward vector by normalized difference between player character and the target on the XZ plane
|
// the forward vector by normalized difference between player character and the target on the XZ plane
|
||||||
Vector3 const pos_flat{this->get_global_position().x, 0.f, this->get_global_position().z};
|
Vector3 const pos_flat{this->get_global_position().x, 0.f, this->get_global_position().z};
|
||||||
Vector3 const target_flat{at.x, 0.f, at.z};
|
Vector3 const target_flat{at.x, 0.f, at.z};
|
||||||
Vector3 const muzzle_flat{this->weapon_muzzle->get_global_position().x, 0.f, this->weapon_muzzle->get_global_position().z};
|
Vector3 const muzzle_flat{this->weapon_muzzle->get_global_position().x, 0.f, this->weapon_muzzle->get_global_position().z};
|
||||||
|
@ -105,7 +104,6 @@ void CharacterActor::set_firing(bool firing) {
|
||||||
void CharacterActor::set_manual_mode(bool value) {
|
void CharacterActor::set_manual_mode(bool value) {
|
||||||
this->mode_manual = value;
|
this->mode_manual = value;
|
||||||
ProcessMode const mode = value ? ProcessMode::PROCESS_MODE_DISABLED : ProcessMode::PROCESS_MODE_PAUSABLE;
|
ProcessMode const mode = value ? ProcessMode::PROCESS_MODE_DISABLED : ProcessMode::PROCESS_MODE_PAUSABLE;
|
||||||
//this->nav_agent->set_process_mode(mode);
|
|
||||||
this->nav_agent->set_avoidance_priority(value ? 1.f : 0.9f);
|
this->nav_agent->set_avoidance_priority(value ? 1.f : 0.9f);
|
||||||
this->set_state(goap::State::new_invalid());
|
this->set_state(goap::State::new_invalid());
|
||||||
}
|
}
|
||||||
|
@ -259,35 +257,30 @@ void CharacterActor::process_behaviour(double delta_time) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void CharacterActor::process_navigation(double delta_time) {
|
void CharacterActor::process_navigation(double delta_time) {
|
||||||
float const distance_sqr = this->nav_agent->get_target_position().distance_squared_to(this->get_global_position());
|
float const sqr_dist = this->nav_agent->get_target_position().distance_squared_to(this->get_global_position());
|
||||||
float const distance_target_sqr = std::pow(this->nav_agent->get_target_desired_distance(), 2.f);
|
float const sqr_dist_target = Math::pow(this->nav_agent->get_target_desired_distance(), 2.0);
|
||||||
if(!this->nav_agent->is_navigation_finished() && distance_sqr >= distance_target_sqr) {
|
if(this->nav_agent->is_navigation_finished() || sqr_dist < sqr_dist_target)
|
||||||
Vector3 const target_position = this->nav_agent->get_next_path_position();
|
return;
|
||||||
Vector3 const direction = (target_position - this->get_global_position()).normalized();
|
Vector3 const target_pos = this->nav_agent->get_next_path_position();
|
||||||
|
Vector3 const direction = (target_pos - this->get_global_position()).normalized();
|
||||||
if(this->nav_agent->get_avoidance_enabled())
|
if(this->nav_agent->get_avoidance_enabled())
|
||||||
this->nav_agent->set_velocity(direction * CharacterActor::walk_speed);
|
this->nav_agent->set_velocity(direction * CharacterActor::walk_speed);
|
||||||
else
|
else
|
||||||
this->move(direction);
|
this->move(direction);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CharacterActor::process_rotation(double delta_time) {
|
void CharacterActor::process_rotation(double delta_time) {
|
||||||
// copy the current transform and basis matrix
|
Basis basis = this->get_global_basis();
|
||||||
Transform3D trans{this->get_global_transform()};
|
|
||||||
Basis basis = trans.get_basis();
|
|
||||||
// construct the current rotation ..
|
|
||||||
Quaternion const current_quaternion = basis.get_rotation_quaternion();
|
Quaternion const current_quaternion = basis.get_rotation_quaternion();
|
||||||
// .. and the target rotation from their respective bases
|
|
||||||
Quaternion const target_quaternion = this->target_rotation.get_rotation_quaternion();
|
Quaternion const target_quaternion = this->target_rotation.get_rotation_quaternion();
|
||||||
// calculate the angle that still needs to be traveled
|
// the angle that still needs to be traveled
|
||||||
float const angle = current_quaternion.angle_to(target_quaternion);
|
float const angle = current_quaternion.angle_to(target_quaternion);
|
||||||
// calculate the angle amount that can be moved this frame
|
// calculate the angle amount that can be moved this frame
|
||||||
float const angle_step{float(this->rotation_speed_curve->sample(angle) * CharacterActor::rotation_speed * delta_time)};
|
float const step{float(this->rotation_speed_curve->sample(angle) * CharacterActor::rotation_speed * delta_time)};
|
||||||
// update this object's global transform with the new rotation
|
// update this object's global transform with the new rotation
|
||||||
basis.set_quaternion(angle < angle_step ? target_quaternion // to avoid overshooting, check if the max step is smaller than the angle distance
|
basis.set_quaternion(angle < step ? target_quaternion // to avoid overshooting, check if the max step is smaller than the angle distance
|
||||||
: current_quaternion.slerp(target_quaternion, angle_step / angle)); // convert the angle step to a lerp t value between current and target rotations
|
: current_quaternion.slerp(target_quaternion, step / angle)); // convert the angle step to a lerp t value between current and target rotations
|
||||||
trans.set_basis(basis);
|
this->set_global_basis(basis);
|
||||||
this->set_global_transform(trans);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CharacterActor::try_fire_weapon() {
|
void CharacterActor::try_fire_weapon() {
|
||||||
|
|
Loading…
Reference in a new issue