inching towards better class inheritence and multiplayer compatibility
This commit is contained in:
34
Scripts/Projectiles/explosive_projectile.gd
Normal file
34
Scripts/Projectiles/explosive_projectile.gd
Normal file
@ -0,0 +1,34 @@
|
||||
extends Projectile
|
||||
class_name ExplosiveProjectile
|
||||
|
||||
@export var explosion_range := 3.0
|
||||
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
super._process(delta)
|
||||
if time_alive >= lifetime:
|
||||
explode()
|
||||
|
||||
|
||||
func _on_body_entered(_body: Node) -> void:
|
||||
explode()
|
||||
|
||||
|
||||
func explode():
|
||||
if is_multiplayer_authority():
|
||||
for enemy in get_tree().get_nodes_in_group("Enemies"):
|
||||
if global_position.distance_to(enemy.global_position) <= explosion_range:
|
||||
hit(enemy)
|
||||
networked_hit.rpc(get_tree().root.get_path_to(enemy))
|
||||
networked_kill.rpc()
|
||||
queue_free()
|
||||
|
||||
|
||||
func hit(target):
|
||||
target.damage(damage)
|
||||
|
||||
|
||||
@rpc("reliable")
|
||||
func networked_hit(target_node_path):
|
||||
var target = get_tree().root.get_node(target_node_path)
|
||||
hit(target)
|
17
Scripts/Projectiles/homing_projectile.gd
Normal file
17
Scripts/Projectiles/homing_projectile.gd
Normal file
@ -0,0 +1,17 @@
|
||||
extends ExplosiveProjectile
|
||||
class_name HomingProjectile
|
||||
|
||||
var target : Node3D
|
||||
@export var acceleration := 40.0
|
||||
@export var max_speed := 14.0
|
||||
|
||||
|
||||
func _physics_process(_delta: float) -> void:
|
||||
if is_instance_valid(target):
|
||||
direction = global_position.direction_to(target.global_position)
|
||||
#apply_central_force(direction * acceleration)
|
||||
|
||||
|
||||
func _integrate_forces(state: PhysicsDirectBodyState3D) -> void:
|
||||
state.linear_velocity += direction * acceleration * state.step
|
||||
state.linear_velocity = state.linear_velocity.limit_length(max_speed)
|
23
Scripts/Projectiles/projectile.gd
Normal file
23
Scripts/Projectiles/projectile.gd
Normal file
@ -0,0 +1,23 @@
|
||||
extends RigidBody3D
|
||||
class_name Projectile
|
||||
|
||||
@export var collision_shape : CollisionShape3D
|
||||
|
||||
var direction := Vector3.FORWARD
|
||||
var force := 2.0
|
||||
var damage := 0.0
|
||||
var lifetime := 10.0
|
||||
var time_alive := 0.0
|
||||
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
time_alive += delta
|
||||
|
||||
|
||||
func _on_body_entered(_body: Node) -> void:
|
||||
pass # Replace with function body.
|
||||
|
||||
|
||||
@rpc("reliable")
|
||||
func networked_kill():
|
||||
queue_free()
|
15
Scripts/Projectiles/status_applying_projectile.gd
Normal file
15
Scripts/Projectiles/status_applying_projectile.gd
Normal file
@ -0,0 +1,15 @@
|
||||
extends ExplosiveProjectile
|
||||
class_name StatusApplyingProjectile
|
||||
|
||||
@export var status_stats : StatusStats
|
||||
|
||||
|
||||
func hit(target):
|
||||
super.hit(target)
|
||||
target.status_manager.add_effect(build_status_object())
|
||||
|
||||
|
||||
func build_status_object() -> StatusEffect:
|
||||
var status = StatusEffect.new()
|
||||
status.stats = status_stats
|
||||
return status
|
Reference in New Issue
Block a user