summaryrefslogtreecommitdiff
path: root/scenes/ballistics/Rocket.gd
diff options
context:
space:
mode:
Diffstat (limited to 'scenes/ballistics/Rocket.gd')
-rw-r--r--scenes/ballistics/Rocket.gd64
1 files changed, 64 insertions, 0 deletions
diff --git a/scenes/ballistics/Rocket.gd b/scenes/ballistics/Rocket.gd
new file mode 100644
index 0000000..56438a2
--- /dev/null
+++ b/scenes/ballistics/Rocket.gd
@@ -0,0 +1,64 @@
+extends RigidBody
+
+onready var world = get_tree().get_root().find_node("GAMEWORLD", true, false)
+
+var shooter = "WORLD"
+
+export var lifetime : float = 2.0
+export var strength : int = 80
+
+var life = 0.0
+var cannot_explode = false
+
+func _ready():
+ $RocketTrail.emitting = true
+
+func get_init_info():
+ return {"linear_velocity" : linear_velocity, "angular_velocity" : angular_velocity, "life" : life, "shooter" : shooter}
+
+func mp_init(init_info):
+ for variable in init_info.keys():
+ set(variable, init_info[variable])
+
+remotesync func update_phys_transform(t, lv, av):
+ transform = t
+ linear_velocity = lv
+ angular_velocity = av
+
+func _physics_process(delta):
+ if life < lifetime:
+ add_central_force(global_transform.basis.x*strength)
+ life += delta
+ else:
+ explode()
+ $RocketTrail.emitting = false
+
+func _integrate_forces(state):
+ if is_network_master():
+ rpc("update_phys_transform", transform, linear_velocity, angular_velocity)
+
+func explode():
+ if cannot_explode:
+ return
+ cannot_explode = true
+ $RocketTrail.emitting = false
+ $rocket_mesh.visible = false
+ mode = MODE_STATIC
+ set_collision_layer_bit(1,0)
+ set_collision_mask_bit(1,0)
+
+ var expl = preload("res://particles/p_Explosion.tscn").instance()
+ world.add_child(expl)
+ expl.init(global_transform.origin, Vector3.ZERO)
+
+
+ for body in $BlastArea.get_overlapping_bodies():
+ if body.has_method("damage") and is_network_master():
+ body.rpc("damage", 50, "explosive", shooter, "using 'rocket'")
+ body.apply_central_impulse((1500*(global_transform.origin - body.global_transform.origin).normalized()))
+ body.rpc("apply_central_impulse", (1500*(global_transform.origin - body.global_transform.origin).normalized()))
+
+ $AnimationPlayer.play("explode")
+
+func _on_collision(body):
+ explode()