summaryrefslogtreecommitdiff
path: root/src/player_controller/playercontroller.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/player_controller/playercontroller.cpp')
-rw-r--r--src/player_controller/playercontroller.cpp69
1 files changed, 40 insertions, 29 deletions
diff --git a/src/player_controller/playercontroller.cpp b/src/player_controller/playercontroller.cpp
index e14aa5e..71ccaa0 100644
--- a/src/player_controller/playercontroller.cpp
+++ b/src/player_controller/playercontroller.cpp
@@ -30,6 +30,8 @@ void PlayerController::_register_methods() {
register_method("mount_ladder", &PlayerController::mount_ladder);
register_method("climb_ladder", &PlayerController::climb_ladder);
register_method("leave_ladder", &PlayerController::leave_ladder);
+ register_method("get_head", &PlayerController::get_head);
+ register_method("get_neck", &PlayerController::get_neck);
register_method("damage", &PlayerController::damage, GODOT_METHOD_RPC_MODE_REMOTESYNC);
register_method("remove_dead_character", &PlayerController::remove_dead_character, GODOT_METHOD_RPC_MODE_REMOTESYNC);
register_method("net_apply_impulse", &PlayerController::net_apply_impulse, GODOT_METHOD_RPC_MODE_REMOTESYNC);
@@ -78,7 +80,7 @@ void PlayerController::_ready() {
weapon = (Node *)p->instance();
add_child(weapon);
world = get_tree()->get_root()->get_node<Spatial>("GAMEWORLD");
- cam = (PlayerCam *)world->call("get_cam");
+ cam = (Camera *)world->call("get_cam");
}
Dictionary PlayerController::get_init_info() {
@@ -105,6 +107,13 @@ void PlayerController::_process(float _delta) {
if(input_singleton->is_action_just_pressed("fire"))machine->call("attack1");
if(input_singleton->is_action_just_pressed("fire2"))machine->call("attack2");
}
+ else {
+ jumping = input_singleton->get_action_strength("move_jump");
+ //if(input_singleton->is_action_just_pressed("fire"))
+ // weapon->call("attack1");
+ move_axis.x = input_singleton->get_action_strength("move_forward") - input_singleton->get_action_strength("move_backward");
+ move_axis.y = input_singleton->get_action_strength("move_right") - input_singleton->get_action_strength("move_left");
+ }
}
}
@@ -122,29 +131,29 @@ void PlayerController::initiate_use() {
}
}
-void PlayerController::set_net_owner(int owner_id) {
+void PlayerController::set_net_owner(Variant owner_id) {
nametag->set_text("");
set_network_master(owner_id);
- if(owner_id != 1)
+ if(owner_id != Variant(1))
nametag->set_text(String(world->call("get_players_info", owner_id, 0)));
if(get_tree()->get_network_unique_id() != 1){
- if(owner_id == (int)world->call("get_client_id")){
+ if(owner_id == world->call("get_client_id")){
nametag->set_visible(false);
world->call("set_player_char", this);
is_player = true;
- cam->attach(this, "FIRSTPERSON", "./Neck/Head");
+ cam->call("attach", (RigidBody*)this, String("FIRSTPERSON"), String("./Neck/Head"));
}else{
nametag->set_visible(true);
is_player = false;
}
- world->get_node("HUD")->call("update_characters");
+ world->get_node(NodePath("./HUD"))->call("update_characters");
}
}
void PlayerController::deselect_character() {
if(is_network_master()){
world->call("set_player_char", "NULL");
- if((int)world->call("get_client_id") != 1)cam->attach(world, "STATIC", "./DEFAULTCAM");
+ if((int)world->call("get_client_id") != 1)cam->call("attach",world, "STATIC", "./DEFAULTCAM");
rpc("set_net_owner", 1);
}
}
@@ -155,7 +164,7 @@ void PlayerController::take_control_of_machine(RigidBody *slave_machine) {
}
void PlayerController::lose_machine() {
- if(is_network_master())cam->attach(this, "FIRSTPERSON", "./Neck/Head");
+ if(is_network_master())cam->call("attach", this, "FIRSTPERSON", "./Neck/Head");
controlling_machine = false;
machine = nullptr;
}
@@ -212,26 +221,27 @@ void PlayerController::_integrate_forces(PhysicsDirectBodyState *state) {
}
void PlayerController::walk(float _delta) {
-// # Input
-// direction = Vector3()
-// var aim: Basis = head.get_global_transform().basis
-// direction += -move_axis.x * aim.z + move_axis.y * aim.x
-// direction.y = 0
-// direction = direction.normalized()
-//
-// if floor_normal != Vector3.UP: direction = direction.rotated(floor_normal.cross(Vector3.UP).normalized(), Vector3.UP.angle_to(floor_normal))
-//
-// # Jump
-// if is_player and jumping and is_on_floor and can_jump:
-// jump()
-//
-// #max walk speed
-// var _speed = walk_speed
-// var _temp_accel: float = acceleration
-// var _cspeed = sqrt(pow(velocity.x-floorspeed.x,2)+pow(velocity.z-floorspeed.z,2))
-//
-// if not is_on_floor:
-// _temp_accel *= air_control
+ Basis aim = head->get_global_transform().basis;
+ direction = -move_axis.x * aim.z + move_axis.y * aim.x;
+ direction.y = 0;
+ direction = direction.normalized();
+
+ //if(floor_normal != Vector3::UP) direction = direction.rotated(floor_normal.cross(Vector3::UP).normalized(), Vector3::UP.angle_to(floor_normal)).normalized();
+ if(is_player && jumping && is_on_floor && can_jump){Godot::print("jump"); jump();}
+ float temp_accel = is_on_floor ? acceleration : acceleration * air_control;
+ float cspeed = sqrt(pow(velocity.x-floorspeed.x,2)+pow(velocity.z-floorspeed.z,2));
+
+ float proj_vel = Vector2(velocity.x-floorspeed.x,velocity.z-floorspeed.z).dot(Vector2(direction.x,direction.z));
+ if(is_on_floor) {
+ if(get_network_master() != 1)Godot::print(direction);
+ add_central_force(-get_mass()*cspeed*get_linear_velocity().normalized()*c_friction);
+ if(walk_speed - cspeed > 0)
+ add_central_force (get_mass()*Vector3(direction.x*temp_accel, 0, direction.z*temp_accel));
+ else
+ add_central_force(get_mass()*Vector3(direction.x*(walk_speed-proj_vel), 0, direction.z*(walk_speed-proj_vel)));
+ }
+ else if (1.0 - proj_vel > 0.0)
+ add_central_force(get_mass()*Vector3(direction.x*temp_accel, 0, direction.z*temp_accel));
}
void PlayerController::jump() {
@@ -322,4 +332,5 @@ void PlayerController::net_apply_impulse(Vector3 impulse_v) {
apply_central_impulse(impulse_v);
}
-
+Spatial* PlayerController::get_head() { return head; }
+Spatial* PlayerController::get_neck() { return neck; }