diff options
| author | Anson Bridges <bridges.anson@gmail.com> | 2022-09-04 14:57:56 -0700 |
|---|---|---|
| committer | Anson Bridges <bridges.anson@gmail.com> | 2022-09-04 14:57:56 -0700 |
| commit | a0967ebe815cd229b69fb9578f2288b95b2ddb28 (patch) | |
| tree | ce1b06b1d8226c64e3550d674df96a2308f18130 /scripts/machines | |
| parent | 5dbe6302e437c5c1d4431b853c410aa1d52f9b3d (diff) | |
networked machine project. added broken airplane from previous project
Diffstat (limited to 'scripts/machines')
| -rw-r--r-- | scripts/machines/Cannon.gd | 64 | ||||
| -rw-r--r-- | scripts/machines/NetworkedMachine.gd | 54 |
2 files changed, 72 insertions, 46 deletions
diff --git a/scripts/machines/Cannon.gd b/scripts/machines/Cannon.gd index e7a5441..3cf6f5d 100644 --- a/scripts/machines/Cannon.gd +++ b/scripts/machines/Cannon.gd @@ -1,12 +1,10 @@ -extends RigidBody -#Basis -var in_use : bool = false -var user = null -var world = null +extends "res://scripts/machines/NetworkedMachine.gd" + +var world_ballistics = null var cooldown = 0 export var fire_rate = 1 #shot/s -export var ball_speed = 500 #m/s +export var ball_speed = 400 #m/s var pitch :float = 0.0 var turn :float = 0.0 @@ -21,10 +19,9 @@ export var max_yaw = 15 onready var muzzle = get_node("YawJoint/PitchJoint/Muzzle") -remote func update_phys_transform(t, lv, av): - transform = t - linear_velocity = lv - angular_velocity = av +remote func update_aim(pitch_z, yaw_y): + $YawJoint/PitchJoint.rotation_degrees.z = pitch_z + $YawJoint.rotation_degrees.y = yaw_y func get_init_info(): return {"pitch_rot" : $YawJoint/PitchJoint.rotation_degrees.z, "turn_rot" : $YawJoint.rotation_degrees.y, "in_use" : in_use} @@ -39,48 +36,25 @@ func _ready(): if get_parent().name != "MACHINES": add_collision_exception_with(get_parent()) mode = RigidBody.MODE_STATIC - world = get_tree().get_root().find_node("BALLISTICS", true, false) - -remotesync func set_net_owner(id, char_name): - set_network_master(id) - if id != 1 or char_name != "NONE": - pass - -func is_in_use(): - return in_use - -func take_control(controller): + world_ballistics = world.get_node("BALLISTICS") + +func on_new_control(): $YawJoint/PitchJoint/Camera.current = true - user = controller - in_use = true - return self - -func relinquish_control(): - in_use = false - user = null - rpc("set_owner", 1, "NONE") func _physics_process(delta): if cooldown > 0: cooldown -= delta - if in_use: - #aim + if in_use and is_network_master(): #aim $YawJoint/PitchJoint.rotation_degrees.z += pitch*pitch_speed*delta $YawJoint.rotation_degrees.y += turn*turn_speed*delta - if $YawJoint.rotation_degrees.y > max_yaw: - $YawJoint.rotation_degrees.y = max_yaw - elif $YawJoint.rotation_degrees.y < min_yaw: - $YawJoint.rotation_degrees.y = min_yaw - if $YawJoint/PitchJoint.rotation_degrees.z > max_pitch: - $YawJoint/PitchJoint.rotation_degrees.z = max_pitch - elif $YawJoint/PitchJoint.rotation_degrees.z < min_pitch: - $YawJoint/PitchJoint.rotation_degrees.z = min_pitch - if is_network_master() and mode == MODE_STATIC: - rpc("update_phys_transform", transform, linear_velocity, angular_velocity) + $YawJoint.rotation_degrees.y = clamp($YawJoint.rotation_degrees.y, min_yaw, max_yaw) + $YawJoint/PitchJoint.rotation_degrees.z = clamp($YawJoint/PitchJoint.rotation_degrees.z, min_pitch, max_pitch) + + rpc("update_aim", $YawJoint/PitchJoint.rotation_degrees.z, $YawJoint.rotation_degrees.y) func direction_input(fwd,bwd,left,right,_left,_right): pitch = fwd - bwd - turn = left - right + turn = right - left func attack1(): if cooldown > 0: @@ -91,8 +65,9 @@ remotesync func fire(): $YawJoint/PitchJoint/Muzzle/explosion_sound.play() var expl = preload("res://particles/p_Explosion.tscn").instance() var cball = preload("res://scenes/ballistics/Cannonball.tscn").instance() - world.add_child(cball) + world_ballistics.add_child(cball, true) world.add_child(expl) + expl.scale = Vector3(0.25,0.25,0.25) expl.init(muzzle.global_transform.origin, Vector3.ZERO) add_collision_exception_with(cball) cball.global_transform.origin = muzzle.global_transform.origin @@ -102,6 +77,3 @@ remotesync func fire(): get_parent().apply_impulse($YawJoint/PitchJoint.global_transform.origin - get_parent().global_transform.origin, -1*cball.mass*ball_speed*muzzle.global_transform.basis.x) else: apply_impulse($YawJoint/PitchJoint.global_transform.origin - global_transform.origin, -1*cball.mass*ball_speed*muzzle.global_transform.basis.x) - -func attack2(): - pass diff --git a/scripts/machines/NetworkedMachine.gd b/scripts/machines/NetworkedMachine.gd new file mode 100644 index 0000000..d4ccb61 --- /dev/null +++ b/scripts/machines/NetworkedMachine.gd @@ -0,0 +1,54 @@ +extends RigidBody + +var in_use : bool = false +var user = null +var world = null + +func _ready(): + world = get_tree().get_root().find_node("GAMEWORLD", true, false) + +remote func update_phys_transform(t, lv, av): + transform = t + linear_velocity = lv + angular_velocity = av + +remotesync func net_apply_impulse(impulse_v): + apply_central_impulse(impulse_v) + +func _integrate_forces(state): + if is_network_master() and mode == MODE_RIGID: + rpc("update_phys_transform", transform, linear_velocity, angular_velocity) + +remotesync func set_net_owner(id, char_name): + set_network_master(id) + if id == 1 and char_name == "NONE": #not under control + on_no_control() + if user != null: + user.lose_machine() + user = null + in_use = false + else: + in_use = true + user = world.get_node("PLAYERS/"+char_name) + user.take_control_of_machine(self) + if is_network_master(): + on_new_control() + +func relinquish_control(): + rpc("set_net_owner", 1, "NONE") + +#TO BE OVERRIDDEN BY CHILDREN +func on_new_control(): + pass + +func on_no_control(): + pass + +func attack1(): + pass + +func attack2(): + pass + +func direction_input(fwd,bwd,left,right,_left,_right): + pass |
