diff options
| author | Anson Bridges <bridges.anson@gmail.com> | 2022-09-07 14:07:30 -0400 |
|---|---|---|
| committer | Anson Bridges <bridges.anson@gmail.com> | 2022-09-07 14:07:30 -0400 |
| commit | c232b92e2dde1277324d1f89d0e75ae641e4ac3b (patch) | |
| tree | e11a5dd52f259c1cc7345baa40b372b304417f00 /godot/scripts/machines/Cannon.gd | |
| parent | a0967ebe815cd229b69fb9578f2288b95b2ddb28 (diff) | |
reorganized, ladders, vehicle control
Diffstat (limited to 'godot/scripts/machines/Cannon.gd')
| -rw-r--r-- | godot/scripts/machines/Cannon.gd | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/godot/scripts/machines/Cannon.gd b/godot/scripts/machines/Cannon.gd new file mode 100644 index 0000000..6b636c5 --- /dev/null +++ b/godot/scripts/machines/Cannon.gd @@ -0,0 +1,79 @@ +extends "res://scripts/machines/NetworkedMachine.gd" + +var world_ballistics = null + +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 + +export var turn_speed = 7.5 #deg/s +export var pitch_speed = 10 + +export var max_pitch = 50 +export var min_pitch = -10 +export var min_yaw = -15 +export var max_yaw = 15 + +onready var muzzle = get_node("YawJoint/PitchJoint/Muzzle") + +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} + +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"] + +# Called when the node enters the scene tree for the first time. +func _ready(): + if get_parent().name != "MACHINES": + add_collision_exception_with(get_parent()) + mode = RigidBody.MODE_STATIC + world_ballistics = world.get_node("BALLISTICS") + +func on_new_control(): + $YawJoint/PitchJoint/Camera.current = true + +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 + $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 = right - left + +func attack1(): + if cooldown > 0: + return + rpc("fire") + +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_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 + cball.linear_velocity = muzzle.global_transform.basis.x*ball_speed + cooldown = fire_rate + if mode == RigidBody.MODE_STATIC: + get_parent().apply_impulse($YawJoint/PitchJoint.global_transform.origin - get_parent().global_transform.origin, -5*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) |
