generated from Persson-dev/Godot-Xmake
begin network
This commit is contained in:
@@ -23,11 +23,9 @@ Player::~Player() {}
|
||||
|
||||
void Player::_ready() {
|
||||
godot::InputMap::get_singleton()->load_from_project_settings();
|
||||
m_PlayerMesh = Object::cast_to<godot::Node3D>(get_child(0));
|
||||
m_SpringArmPivot = Object::cast_to<godot::Node3D>(get_child(2));
|
||||
m_AnimationTree = Object::cast_to<godot::AnimationTree>(get_child(4));
|
||||
m_PlayerMesh = Object::cast_to<godot::Node3D>(find_child("Mesh"));
|
||||
m_AnimationTree = Object::cast_to<godot::AnimationTree>(find_child("AnimationTree"));
|
||||
DEV_ASSERT(m_PlayerMesh);
|
||||
DEV_ASSERT(m_SpringArmPivot);
|
||||
DEV_ASSERT(m_AnimationTree);
|
||||
|
||||
apply_floor_snap();
|
||||
@@ -39,47 +37,6 @@ void Player::_physics_process(float delta) {
|
||||
return;
|
||||
|
||||
|
||||
auto* Input = godot::Input::get_singleton();
|
||||
godot::Vector3 move_direction{0, 0, 0};
|
||||
move_direction.x = Input->get_action_strength("move_right") - Input->get_action_strength("move_left");
|
||||
move_direction.z = Input->get_action_strength("move_backwards") - Input->get_action_strength("move_forwards");
|
||||
move_direction = move_direction.rotated({0, 1, 0}, m_SpringArmPivot->get_rotation().y);
|
||||
|
||||
godot::Vector3 newVelocity = get_velocity();
|
||||
newVelocity.y -= Gravity * delta;
|
||||
set_velocity(newVelocity);
|
||||
|
||||
|
||||
|
||||
if (Input->is_action_pressed("run"))
|
||||
m_Speed = RunSpeed;
|
||||
else
|
||||
m_Speed = WalkSpeed;
|
||||
|
||||
newVelocity = get_velocity();
|
||||
newVelocity.x = move_direction.x * m_Speed;
|
||||
newVelocity.z = move_direction.z * m_Speed;
|
||||
set_velocity(newVelocity);
|
||||
|
||||
if (move_direction != godot::Vector3{0, 0, 0}) {
|
||||
godot::Vector3 newRotation = m_PlayerMesh->get_rotation();
|
||||
newRotation.y = godot::UtilityFunctions::lerp_angle(
|
||||
newRotation.y, godot::UtilityFunctions::atan2(get_velocity().x, get_velocity().z), LerpValue);
|
||||
m_PlayerMesh->set_rotation(newRotation);
|
||||
}
|
||||
|
||||
bool justLanded = is_on_floor() && m_SnapVector == godot::Vector3{0, 0, 0};
|
||||
bool isJumping = is_on_floor() && Input->is_action_just_pressed("jump");
|
||||
|
||||
if (isJumping) {
|
||||
newVelocity = get_velocity();
|
||||
newVelocity.y = JumpStrength;
|
||||
set_velocity(newVelocity);
|
||||
m_SnapVector.zero();
|
||||
} else if (justLanded) {
|
||||
m_SnapVector = {0, -1, 0};
|
||||
}
|
||||
|
||||
apply_floor_snap();
|
||||
move_and_slide();
|
||||
animate(delta);
|
||||
|
||||
Reference in New Issue
Block a user