From 508c90f61190295183a7640125a0c0168d6e9c4c Mon Sep 17 00:00:00 2001 From: TechieDamien Date: Sun, 4 Jul 2021 19:05:33 +0100 Subject: [PATCH] Changed targeting system to use cone --- Models/Cone.obj | 3 ++ Models/Cone.obj.import | 3 ++ Models/Material_001.material | 4 +- Models/Material_002.material | 4 +- Models/cone-collision.tres | 3 ++ Scenes/Player.tscn | 23 ++++++++-- Scripts/Player.gd | 73 ++++++++++++++++++++++-------- Shaders/OutsideSpaceship.material | Bin 836 -> 837 bytes export_presets.cfg | 18 ++++---- project.godot | 1 + 10 files changed, 94 insertions(+), 38 deletions(-) create mode 100644 Models/Cone.obj create mode 100644 Models/Cone.obj.import create mode 100644 Models/cone-collision.tres diff --git a/Models/Cone.obj b/Models/Cone.obj new file mode 100644 index 0000000..f46d05c --- /dev/null +++ b/Models/Cone.obj @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:37a1fdfb98f374944c10bb40a3af9b4566917e4353f6fd9da52802da33d92633 +size 2032 diff --git a/Models/Cone.obj.import b/Models/Cone.obj.import new file mode 100644 index 0000000..d3f8daa --- /dev/null +++ b/Models/Cone.obj.import @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a48eeb5e6b11a251d372273f860addc8e0523ba9e15eda830d141de844e0e31d +size 489 diff --git a/Models/Material_001.material b/Models/Material_001.material index 7cd74ce..0cc83be 100644 --- a/Models/Material_001.material +++ b/Models/Material_001.material @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:339e75ee79c98e0c6ab55c76c747a9f14afc0954f8ffbdc0552dca374556ba1f -size 728 +oid sha256:20f19baac0a048991d3e988ee29775afbd2a5f05581de13cc7d3e64fddfd28e3 +size 729 diff --git a/Models/Material_002.material b/Models/Material_002.material index dcec47c..7dc28af 100644 --- a/Models/Material_002.material +++ b/Models/Material_002.material @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:f468728890627c07ab6f93b29c3cfc670b179b54c39de5c33bd9f5e6530e1be6 -size 829 +oid sha256:063b630bfbbe43e689fd6f9e5871eae2196b1bf8c8c4b24f427d19585602610b +size 831 diff --git a/Models/cone-collision.tres b/Models/cone-collision.tres new file mode 100644 index 0000000..ba7efee --- /dev/null +++ b/Models/cone-collision.tres @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c358d4b73112aa33450e7f9d7713679fcfe8ae95e32386188e53fb0397e6a562 +size 1922 diff --git a/Scenes/Player.tscn b/Scenes/Player.tscn index e15364d..4e80e91 100644 --- a/Scenes/Player.tscn +++ b/Scenes/Player.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=17 format=2] +[gd_scene load_steps=18 format=2] [ext_resource path="res://Scripts/Player.gd" type="Script" id=1] [ext_resource path="res://Models/Arrow.obj" type="ArrayMesh" id=2] @@ -13,6 +13,7 @@ [ext_resource path="res://Images/BatteryBolt.png" type="Texture" id=11] [ext_resource path="res://Images/BatteryFilling.png" type="Texture" id=12] [ext_resource path="res://Images/BatteryBackground.png" type="Texture" id=13] +[ext_resource path="res://Models/cone-collision.tres" type="Shape" id=14] [sub_resource type="CapsuleShape" id=1] radius = 0.15 @@ -465,18 +466,29 @@ anims/ShowEndTurnBanner = ExtResource( 9 ) [node name="GunContainer" type="Spatial" parent="."] transform = Transform( -4.37114e-09, 4.37114e-09, 0.1, 0.1, -4.37114e-09, 4.37114e-09, 4.37114e-09, 0.1, -4.37114e-09, 0, -0.0222926, 0.382747 ) -visible = false + +[node name="Cone" type="Area" parent="GunContainer"] +transform = Transform( 1, -1.77636e-14, 1.91069e-15, 1.77636e-14, 1, -1.77636e-14, -1.91069e-15, 1.77636e-14, 1, 1.19209e-07, 2.66684, -1.16571e-07 ) +input_ray_pickable = false +gravity = 0.0 +linear_damp = 0.0 +angular_damp = 0.0 + +[node name="CollisionShape" type="CollisionShape" parent="GunContainer/Cone"] +transform = Transform( 25, 0, 0, 0, -4.07302e-06, -100, 0, 25, -1.62921e-05, 0, 1000, 0 ) +shape = ExtResource( 14 ) [node name="spaceship-gun" parent="GunContainer" instance=ExtResource( 10 )] transform = Transform( 1, 0, 1.64203e-15, 0, 1, 0, 1.64203e-15, 0, 1, 4.47035e-08, 0.811224, -3.54597e-08 ) [node name="RayCast" type="RayCast" parent="GunContainer"] transform = Transform( 1, 0, 1.64203e-15, 0, 1, 0, 1.64203e-15, 0, 1, 7.45058e-08, 1.76881, -7.73171e-08 ) +visible = false enabled = true -cast_to = Vector3( 0, 500, 0 ) +cast_to = Vector3( 0, 0, -500 ) [node name="CSGCylinder" type="CSGCylinder" parent="GunContainer/RayCast"] -transform = Transform( 1, 0, 1.64203e-15, 0, 1, 0, 1.64203e-15, 0, 1, 0, 30, 0 ) +transform = Transform( 1, 0, 0, 0, -4.37114e-08, -1, 0, 1, -4.37114e-08, 0, 30, 0 ) material_override = SubResource( 3 ) radius = 0.09 height = 60.0 @@ -614,6 +626,7 @@ margin_left = 10.0 margin_top = 10.0 margin_right = -10.0 margin_bottom = -10.0 + [connection signal="mouse_entered" from="." to="." method="_on_Player_mouse_entered"] [connection signal="mouse_exited" from="." to="." method="_on_Player_mouse_exited"] [connection signal="value_changed" from="MainPanel/TimeBar" to="." method="_on_TimeBar_value_changed"] @@ -630,3 +643,5 @@ margin_bottom = -10.0 [connection signal="value_changed" from="ThrustPanel/ZLin" to="." method="_on_ZLin_value_changed"] [connection signal="value_changed" from="ThrustPanel/ZRot" to="." method="_on_ZRot_value_changed"] [connection signal="pressed" from="ThrustPanel/ResetButton" to="." method="_on_ResetButton_pressed"] +[connection signal="body_entered" from="GunContainer/Cone" to="." method="_on_player_enter_firing_arc"] +[connection signal="body_exited" from="GunContainer/Cone" to="." method="_on_player_exit_firing_arc"] diff --git a/Scripts/Player.gd b/Scripts/Player.gd index 975278a..ff78da0 100644 --- a/Scripts/Player.gd +++ b/Scripts/Player.gd @@ -8,6 +8,7 @@ var thrust_plan : Plan = Plan.new() var weapons_plan : Plan = Plan.new() var is_local : bool = false var running_plan : bool = false +var using_full_plan : bool = false var was_running_plan : bool = false var plan_time : float = 0.0 var last_translation : Vector3 = get_translation() @@ -35,6 +36,8 @@ var end_health : float = 100.0 var energy : float = 100.0 var end_energy : float = 100.0 +var players_in_firing_arc = [] + onready var arrow_obj : Spatial = $ArrowContainer onready var arrow_scale_obj : Spatial = $ArrowContainer/ArrowScaleContainer onready var rotate_arrow_obj : Spatial = $RotateArrowContainer @@ -288,7 +291,7 @@ func _physics_process(delta : float) -> void: if !running_plan: if is_local and was_running_plan: get_parent().show_winner() - $GunContainer.visible = false + $GunContainer/RayCast.visible = false arrow_obj.visible = true rotate_arrow_obj.visible = true disable_all_engine_particles() @@ -296,6 +299,19 @@ func _physics_process(delta : float) -> void: set_rotation(last_rotation) was_running_plan = false return + + if !was_running_plan: + players_in_firing_arc = $GunContainer/Cone.get_overlapping_bodies() + if using_full_plan: + set_linear_velocity(initial_velocity) + set_angular_velocity(initial_rotational_velocity) + set_translation(initial_translation) + set_rotation(initial_rotation) + else: + set_linear_velocity(end_linear_velocity) + set_angular_velocity(end_rotational_velocity) + set_translation(end_translation) + set_rotation(end_rotation) was_running_plan = true if time_of_death > 0 and plan_time > time_of_death: @@ -312,6 +328,7 @@ func _physics_process(delta : float) -> void: last_translation = get_translation() last_rotation = get_rotation() running_plan = false + print("thrust plan set running plan to false") return arrow_obj.visible = false rotate_arrow_obj.visible = false @@ -322,16 +339,16 @@ func _physics_process(delta : float) -> void: var all_weapons_elements = _get_all_weapons_elements() var current_weapons_element : WeaponsElement = _get_current_plan_element(all_weapons_elements) if current_weapons_element == null: - $GunContainer.visible = false + $GunContainer/RayCast.visible = false running_plan = false return if current_weapons_element.firing and is_alive: _fire_gun(delta) elif energy < 100: - $GunContainer.visible = false + $GunContainer/RayCast.visible = false energy += BASE_ENERGY_REGEN * delta else: - $GunContainer.visible = false + $GunContainer/RayCast.visible = false calculate_other_damage(delta) plan_time += delta @@ -462,13 +479,10 @@ func update_engine_particles(linear_thrust : Vector3, rotational_thrust : Vector engine_particles2.emitting = false func play_current_plan() -> void: - set_linear_velocity(end_linear_velocity) - set_angular_velocity(end_rotational_velocity) - set_translation(end_translation) - set_rotation(end_rotation) + health = end_health energy = end_energy - + using_full_plan = false running_plan = true plan_time = 5 * turn_counter @@ -476,11 +490,8 @@ func play_all_plans() -> void: get_parent().play_full_plans() func play_full_plan() -> void: - set_linear_velocity(initial_velocity) - set_angular_velocity(initial_rotational_velocity) - set_translation(initial_translation) - set_rotation(initial_rotation) running_plan = true + using_full_plan = true plan_time = 0.0 health = 100.0 energy = 100.0 @@ -493,20 +504,34 @@ func _update_battery_visuals(value : float) -> void: func _update_laser(length : float) -> void: $GunContainer/RayCast/CSGCylinder.height = length*10 - $GunContainer/RayCast/CSGCylinder.translation = Vector3(0, length*5, 0) + $GunContainer/RayCast/CSGCylinder.translation = Vector3(0, 0, -length*5) func _fire_gun(delta : float) -> void: - $GunContainer.visible = true - if $GunContainer/RayCast.is_colliding(): + $GunContainer/RayCast.visible = true + + var closest_enemy = null + var distance_of_closest = -1 + for player in players_in_firing_arc: + if player.player_id == player_id or !player.is_alive: + continue + var player_distance : float = (player.translation - translation).length() + if distance_of_closest == -1 or player_distance < distance_of_closest: + closest_enemy = player + distance_of_closest = player_distance + + + if closest_enemy != null: + $GunContainer/RayCast.look_at($GunContainer/RayCast.global_transform.origin - translation, Vector3(0,1,0)) + #$GunContainer/RayCast.rotate_object_local(Vector3(-1,-1,-1).normalized(), 90.0) var raycast_pos : Vector3 = $GunContainer/RayCast.global_transform.origin var target_pos : Vector3 = $GunContainer/RayCast.get_collision_point() _update_laser(raycast_pos.distance_to(target_pos)) else: - _update_laser($GunContainer/RayCast.cast_to.y) + $GunContainer/RayCast.rotation = Vector3.ZERO + _update_laser(-$GunContainer/RayCast.cast_to.z) energy -= delta * BASE_ENERGY_USAGE - if $GunContainer/RayCast.is_colliding(): - var target : RigidBody = $GunContainer/RayCast.get_collider() - target.take_damage(BASE_DPS * delta) + if closest_enemy != null: + closest_enemy.take_damage(BASE_DPS * delta) func get_display_name() -> String: return get_parent().get_parent().name_dict[player_id] @@ -583,3 +608,11 @@ func fix_plans() -> void: var new_weapons_element : WeaponsElement = WeaponsElement.new() new_weapons_element.firing = false new_weapons_element.time = 5.0 - weapons_plan.current_time() + +func _on_player_enter_firing_arc(body): + players_in_firing_arc.append(body) + print(body.name) + +func _on_player_exit_firing_arc(body): + players_in_firing_arc.erase(body) + print(body.name) diff --git a/Shaders/OutsideSpaceship.material b/Shaders/OutsideSpaceship.material index 6b2caaa1ab4b24eeb5aac8afa6e8d4abe769b656..7365bffeeb6700e198b7f5fe53dc75bce0bf5ec2 100644 GIT binary patch delta 808 zcmV+@1K0e-2E_({Qd2`i0ssI201yBG3I_lHEdu}mD77#BU9suv{g!%f$DU*;#VyfH>Im5c5OuDKtvDNa$7$`wA{~ELBs|E5ChF5 zv^Fgb=CnB*oo!nBTp3HxvrM^^ozFL$8!tqpfZkGScIuaQ^HSQAJAJ3?NU5|r>C4=* zy0q1^Q_L!VpaZq@qcHl4nK~^!m}2(Pz)qL#ZNFlz`JyJ))w|^f0pIll`v3Ig&g7gR z^SGaVor6zao!XYP-B>2&xcRg7aRzF2s+d#dc->dh38*fDChn%rWwcbs+Sc+_Lc{~8 zJv|~Wz-ISdt}=QpJMh8{DL`$xTs>719-Zv8wodd1Y%faPwo3++f&ndmAO>heL_iP; z6c{0ayp3E}zKXK-pG1UsE6b=764Jr-0}%oI+g^@{26VZ6U#2V{mHCwx!~L43XolFt mk9v14y4SIUK=`p2@_1rZW~E*UE}q9wRpBjD&AoO~Q$s^-y>@2+ delta 807 zcmV+?1K9k<2E+z`Qd2`i0ssI201yBG3I_lHECT=lD77#BUXQe))6VCAF8h^3*&amPK=*v=G3pQz z0cL)ix1VZdPFtmP8K_Q|D}L2-aZ|c_V%J7Q4n*{TEw}YEM9ckr6+~eFvaYnft@bf+kVAb^F>Xpt9Q!}0>103=wCg#GdU;7Jnm;- z=irl9r?w?+HF?RW+_Q`bMLu7)y(AkHP&8r8#sH;*%TN_9nV1p#K0}PAXua8$^2suM+)qAnl&IXT z1pq>QV(Qx#^X|-1>nLnH2J8G)yxH_8WKvn>d6tQ#aimb3`E7YFjgtgo@$xtKS4TqC lyO_SWGR@GwVHohxZ