From 7a1d857de96174dfa5a0fa40f8c14acbd2f651c2 Mon Sep 17 00:00:00 2001 From: Anson Bridges Date: Sun, 25 Sep 2022 06:39:12 -0400 Subject: weapons, viewmodels, some performance fixes --- godot/scripts/machines/Cannon.gd | 19 +++++++++++-------- godot/scripts/machines/NetworkedMachineGDS.gd | 1 + 2 files changed, 12 insertions(+), 8 deletions(-) (limited to 'godot/scripts/machines') diff --git a/godot/scripts/machines/Cannon.gd b/godot/scripts/machines/Cannon.gd index b8d9f38..80b9edf 100644 --- a/godot/scripts/machines/Cannon.gd +++ b/godot/scripts/machines/Cannon.gd @@ -6,8 +6,10 @@ var cooldown = 0 export var fire_rate = 1 #shot/s export var ball_speed = 400 #m/s -var pitch :float = 0.0 -var turn :float = 0.0 +var pitch: float = 0.0 +var turn: float = 0.0 + +remotesync var loaded: bool = false export var turn_speed = 7.5 #deg/s export var pitch_speed = 10 @@ -17,19 +19,21 @@ export var min_pitch = -10 export var min_yaw = -15 export var max_yaw = 15 -onready var muzzle = get_node("YawJoint/PitchJoint/Muzzle") +onready var muzzle: Spatial = get_node("YawJoint/PitchJoint/Muzzle") +onready var status: Label3D = get_node("StatusNotifier") 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} + return {"pitch_rot" : $YawJoint/PitchJoint.rotation_degrees.z, "turn_rot" : $YawJoint.rotation_degrees.y, "in_use" : in_use, "loaded" : loaded} func mp_init(init_info): $YawJoint/PitchJoint.rotation_degrees.z = init_info["pitch_rot"] $YawJoint.rotation_degrees.y = init_info["turn_rot"] in_use = init_info["in_use"] + loaded = init_info["loaded"] # Called when the node enters the scene tree for the first time. func _ready(): @@ -42,8 +46,6 @@ func on_new_control(): if is_network_master(): world.cam.attach(self, "STATIC", "./YawJoint/PitchJoint/CameraPoint") func _physics_process(delta): - if cooldown > 0: - cooldown -= delta 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 @@ -57,11 +59,13 @@ func direction_input(fwd,bwd,left,right,_left,_right): turn = right - left func attack1(): - if cooldown > 0: + if !loaded: return rpc("fire") remotesync func fire(): + loaded = false + status.set_visible(true) $YawJoint/PitchJoint/Muzzle/explosion_sound.play() var expl = preload("res://particles/p_Explosion.tscn").instance() var cball = preload("res://scenes/ballistics/Cannonball.tscn").instance() @@ -74,7 +78,6 @@ remotesync func fire(): cball.linear_velocity = muzzle.global_transform.basis.x*ball_speed cball.shooter = user.name + " (" + world.players_info[user.get_network_master()][0] + ")" cball.shooter_id = user.get_network_master() - cooldown = fire_rate if mode == RigidBody.MODE_KINEMATIC: 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: diff --git a/godot/scripts/machines/NetworkedMachineGDS.gd b/godot/scripts/machines/NetworkedMachineGDS.gd index eb675d0..a8ee1da 100644 --- a/godot/scripts/machines/NetworkedMachineGDS.gd +++ b/godot/scripts/machines/NetworkedMachineGDS.gd @@ -1,6 +1,7 @@ extends RigidBody var in_use: bool = false +var controllable: bool = false var user: RigidBody = null var world: Spatial = null -- cgit v1.2.3