diff --git a/addons/top_down/scenes/projectiles/projectile.tscn b/addons/top_down/scenes/projectiles/projectile.tscn index ad52791b..4171cf09 100644 --- a/addons/top_down/scenes/projectiles/projectile.tscn +++ b/addons/top_down/scenes/projectiles/projectile.tscn @@ -1,6 +1,7 @@ -[gd_scene load_steps=13 format=3 uid="uid://beifde6xst23w"] +[gd_scene load_steps=14 format=3 uid="uid://beifde6xst23w"] [ext_resource type="Script" path="res://addons/top_down/scripts/weapon_system/projectile/Projectile2D.gd" id="1_8ha7j"] +[ext_resource type="Resource" uid="uid://dedx0gi4fowby" path="res://addons/top_down/resources/GlobalResources/axis_multiplication_resource.tres" id="2_3gsbh"] [ext_resource type="Texture2D" uid="uid://csfe20i4vc2bk" path="res://addons/top_down/assets/images/projectile/bullet_0.png" id="2_7x3e8"] [ext_resource type="Script" path="res://addons/top_down/scripts/weapon_system/projectile/ProjectileSetup.gd" id="2_yrlmb"] [ext_resource type="Script" path="res://addons/great_games_library/nodes/AreaTransmitter/AreaTransmitter2D.gd" id="3_e2gy5"] @@ -18,7 +19,7 @@ size = Vector2(4, 2) [node name="Projectile" type="Node2D"] script = ExtResource("1_8ha7j") speed = 120.0 -axis_multiplier = Vector2(1, 0.5) +axis_multiplier_resource = ExtResource("2_3gsbh") [node name="ProjectileSetup" type="Node" parent="." node_paths=PackedStringArray("projectile", "area_transmitter", "data_transmitter")] script = ExtResource("2_yrlmb") diff --git a/addons/top_down/scenes/projectiles/sword_slash.tscn b/addons/top_down/scenes/projectiles/sword_slash.tscn index 408901ab..fab95f73 100644 --- a/addons/top_down/scenes/projectiles/sword_slash.tscn +++ b/addons/top_down/scenes/projectiles/sword_slash.tscn @@ -1,9 +1,10 @@ -[gd_scene load_steps=18 format=3 uid="uid://c6ys2qs8aeu8n"] +[gd_scene load_steps=19 format=3 uid="uid://c6ys2qs8aeu8n"] [ext_resource type="PackedScene" uid="uid://beifde6xst23w" path="res://addons/top_down/scenes/projectiles/projectile.tscn" id="1_lwexf"] [ext_resource type="Texture2D" uid="uid://b3gj1j73p318" path="res://addons/top_down/assets/images/shadow.png" id="2_pfam2"] [ext_resource type="PackedScene" uid="uid://djobi3eqlcjvo" path="res://addons/top_down/scenes/vfx/trail_particle.tscn" id="3_gx0bp"] [ext_resource type="Texture2D" uid="uid://br6m3va43cuug" path="res://addons/top_down/assets/images/vfx/slash_3_strip4.png" id="4_u6vsr"] +[ext_resource type="Resource" uid="uid://dedx0gi4fowby" path="res://addons/top_down/resources/GlobalResources/axis_multiplication_resource.tres" id="6_gnksn"] [ext_resource type="Script" path="res://addons/top_down/scripts/weapon_system/projectile/ProjectileSpawner.gd" id="6_whjok"] [ext_resource type="Resource" uid="uid://d1ck1axrd4kd4" path="res://addons/top_down/resources/RoomResources/ysort_reference.tres" id="7_d1e47"] [ext_resource type="Script" path="res://addons/top_down/scripts/weapon_system/projectile/SubProjectileManager.gd" id="7_n74ie"] @@ -134,6 +135,7 @@ autoplay = "slash" [node name="ProjectileSpawner" type="Node" parent="." index="5"] script = ExtResource("6_whjok") +axis_multiplication_resource = ExtResource("6_gnksn") initial_distance = 10.0 projectile_parent_reference = ExtResource("7_d1e47") @@ -142,6 +144,7 @@ script = ExtResource("7_n74ie") projectile = NodePath("..") projectile_spawner = NodePath("../ProjectileSpawner") start_projectile_scene = ExtResource("8_1el3x") +axis_multiplication_resource = ExtResource("6_gnksn") [node name="HitLimit" parent="." index="8"] hit_limit = -1 diff --git a/addons/top_down/scenes/weapons/sword.tscn b/addons/top_down/scenes/weapons/sword.tscn index a14acd39..2357a84d 100644 --- a/addons/top_down/scenes/weapons/sword.tscn +++ b/addons/top_down/scenes/weapons/sword.tscn @@ -87,7 +87,6 @@ interval = 0.3 animation_name = &"" [node name="ProjectileSpawner" parent="." index="4"] -axis_multiplication = Vector2(1, 1) initial_distance = 10.0 projectile_scene = ExtResource("2_x78ie") diff --git a/addons/top_down/scripts/weapon_system/projectile/Projectile2D.gd b/addons/top_down/scripts/weapon_system/projectile/Projectile2D.gd index 9652a3a8..856d7c27 100644 --- a/addons/top_down/scripts/weapon_system/projectile/Projectile2D.gd +++ b/addons/top_down/scripts/weapon_system/projectile/Projectile2D.gd @@ -8,7 +8,7 @@ signal prepare_exit_event ## Direction to travel @export var direction: = Vector2.RIGHT ## Used to fake angled perspective -@export var axis_multiplier:Vector2 = Vector2.ONE +@export var axis_multiplier_resource:Vector2Resource ## Each projectile contribute to the total damage value with multiply @export var damage_multiply:float = 1.0 ## Force pushing a damage receiver @@ -25,10 +25,10 @@ func _ready()->void: move_direction = to_local_direction(direction).normalized() func to_local_direction(dir:Vector2)->Vector2: - return dir * (Vector2.ONE / axis_multiplier) + return dir * (Vector2.ONE / axis_multiplier_resource.value) func _physics_process(delta:float)->void: - global_position += speed * delta * move_direction * axis_multiplier + global_position += speed * delta * move_direction * axis_multiplier_resource.value func prepare_exit()->void: diff --git a/addons/top_down/scripts/weapon_system/projectile/ProjectileSpawner.gd b/addons/top_down/scripts/weapon_system/projectile/ProjectileSpawner.gd index d10602e9..11a78a42 100644 --- a/addons/top_down/scripts/weapon_system/projectile/ProjectileSpawner.gd +++ b/addons/top_down/scripts/weapon_system/projectile/ProjectileSpawner.gd @@ -34,11 +34,12 @@ signal prepare_spawn func spawn()->void: - if !enabled: - return assert(projectile_scene != null, "no projectile scene assigned") assert(projectile_parent_reference.node != null, "projectile parent reference isn't set") + assert(axis_multiplication_resource != null) + if !enabled: + return prepare_spawn.emit() var new_damage_resource:DamageResource diff --git a/addons/top_down/scripts/weapon_system/projectile/SubProjectileManager.gd b/addons/top_down/scripts/weapon_system/projectile/SubProjectileManager.gd index 2a14a243..f956bbf6 100644 --- a/addons/top_down/scripts/weapon_system/projectile/SubProjectileManager.gd +++ b/addons/top_down/scripts/weapon_system/projectile/SubProjectileManager.gd @@ -6,13 +6,15 @@ extends Node ## Scene created and the ready() @export var start_projectile_scene:PackedScene @export var exit_projectile_scene:PackedScene +## Used for extra calculation to simulate angled top-down perspective +@export var axis_multiplication_resource:Vector2Resource var axis_compensation:Vector2 func _ready()->void: # TODO: just a mockup. Need some kind per situation configurations projectile_spawner.collision_mask = Bitwise.append_flags(projectile_spawner.collision_mask, projectile.collision_mask) - axis_compensation = Vector2.ONE / projectile.axis_multiplier + axis_compensation = Vector2.ONE / axis_multiplication_resource.value if start_projectile_scene != null: spawn(start_projectile_scene)