Changed targeting system to use cone
parent
9c3f4a8a26
commit
e9048bc663
|
@ -0,0 +1,4 @@
|
|||
[gd_resource type="ConcavePolygonShape" format=2]
|
||||
|
||||
[resource]
|
||||
data = PoolVector3Array( 0, 0, 10, 0.9511, 0.309, 0, 1, 0, 0, 0, 0, 10, 0.809, 0.5878, 0, 0.9511, 0.309, 0, 0, 0, 10, 0.5878, 0.809, 0, 0.809, 0.5878, 0, 0, 0, 10, 0.309, 0.9511, 0, 0.5878, 0.809, 0, 0, 0, 10, 0, 1, 0, 0.309, 0.9511, 0, 0, 0, 10, -0.309, 0.9511, 0, 0, 1, 0, 0, 0, 10, -0.5878, 0.809, 0, -0.309, 0.9511, 0, 0, 0, 10, -0.809, 0.5878, 0, -0.5878, 0.809, 0, 0, 0, 10, -0.9511, 0.309, 0, -0.809, 0.5878, 0, 0, 0, 10, -1, 0, 0, -0.9511, 0.309, 0, 0, 0, 10, -0.9511, -0.309, 0, -1, 0, 0, 0, 0, 10, -0.809, -0.5878, 0, -0.9511, -0.309, 0, 0, 0, 10, -0.5878, -0.809, 0, -0.809, -0.5878, 0, 0, 0, 10, -0.309, -0.9511, 0, -0.5878, -0.809, 0, 0, 0, 10, 0, -1, 0, -0.309, -0.9511, 0, 0, 0, 10, 0.309, -0.9511, 0, 0, -1, 0, 0, 0, 10, 0.5878, -0.809, 0, 0.309, -0.9511, 0, 0, 0, 10, 0.809, -0.5878, 0, 0.5878, -0.809, 0, 0, 0, 10, 0.9511, -0.309, 0, 0.809, -0.5878, 0, 0, 0, 10, 1, 0, 0, 0.9511, -0.309, 0, 0.9511, 0.309, 0, 0.9511, -0.309, 0, 1, 0, 0, 0.9511, 0.309, 0, 0.809, -0.5878, 0, 0.9511, -0.309, 0, 0.809, 0.5878, 0, 0.809, -0.5878, 0, 0.9511, 0.309, 0, 0.809, 0.5878, 0, 0.5878, -0.809, 0, 0.809, -0.5878, 0, 0.5878, 0.809, 0, 0.5878, -0.809, 0, 0.809, 0.5878, 0, 0.5878, 0.809, 0, 0.309, -0.9511, 0, 0.5878, -0.809, 0, 0.309, 0.9511, 0, 0.309, -0.9511, 0, 0.5878, 0.809, 0, 0.309, 0.9511, 0, 0, -1, 0, 0.309, -0.9511, 0, 0, 1, 0, 0, -1, 0, 0.309, 0.9511, 0, 0, 1, 0, -0.309, -0.9511, 0, 0, -1, 0, -0.309, 0.9511, 0, -0.309, -0.9511, 0, 0, 1, 0, -0.309, 0.9511, 0, -0.5878, -0.809, 0, -0.309, -0.9511, 0, -0.5878, 0.809, 0, -0.5878, -0.809, 0, -0.309, 0.9511, 0, -0.5878, 0.809, 0, -0.809, -0.5878, 0, -0.5878, -0.809, 0, -0.809, 0.5878, 0, -0.809, -0.5878, 0, -0.5878, 0.809, 0, -0.809, 0.5878, 0, -0.9511, -0.309, 0, -0.809, -0.5878, 0, -0.9511, 0.309, 0, -0.9511, -0.309, 0, -0.809, 0.5878, 0, -0.9511, -0.309, 0, -0.9511, 0.309, 0, -1, 0, 0 )
|
|
@ -1,6 +1,7 @@
|
|||
[gd_scene load_steps=3 format=2]
|
||||
[gd_scene load_steps=4 format=2]
|
||||
|
||||
[ext_resource path="res://Scripts/Player.gd" type="Script" id=1]
|
||||
[ext_resource path="res://Models/cone-collision.tres" type="Shape" id=2]
|
||||
|
||||
[sub_resource type="CapsuleShape" id=1]
|
||||
radius = 0.15
|
||||
|
@ -20,3 +21,11 @@ transform = Transform( 2.65431e-15, 1.62921e-08, 0.1, 0.1, -1.62921e-08, 0, 1.62
|
|||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.769, 0 )
|
||||
enabled = true
|
||||
cast_to = Vector3( 0, 500, 0 )
|
||||
|
||||
[node name="Cone" type="Area" parent="GunContainer"]
|
||||
|
||||
[node name="CollisionShape" type="CollisionShape" parent="GunContainer/Cone"]
|
||||
transform = Transform( 25, 0, 1.81899e-12, 4.54747e-13, -4.07302e-06, -100, 5.42101e-20, 25, -1.62921e-05, -1.49012e-08, 1000, -1.33014e-11 )
|
||||
shape = ExtResource( 2 )
|
||||
[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"]
|
||||
|
|
|
@ -15,4 +15,5 @@ __meta__ = {
|
|||
|
||||
[node name="ExitTimer" type="Timer" parent="."]
|
||||
one_shot = true
|
||||
|
||||
[connection signal="timeout" from="ExitTimer" to="." method="end_game"]
|
||||
|
|
|
@ -36,10 +36,12 @@ func _process(delta : float) -> void:
|
|||
player.calculate_plans()
|
||||
|
||||
func generate_translation() -> Vector3:
|
||||
return Vector3(rand_range(-5,5),rand_range(-5,5),rand_range(-5,5))
|
||||
#return Vector3(rand_range(-5,5),rand_range(-5,5),rand_range(-5,5))
|
||||
return Vector3(0,0,rand_range(-5,5))
|
||||
|
||||
func generate_rotation() -> Vector3:
|
||||
return Vector3(rand_range(-1,1),rand_range(-1,1),rand_range(-1,1)).normalized()
|
||||
#return Vector3(rand_range(-1,1),rand_range(-1,1),rand_range(-1,1)).normalized()
|
||||
return Vector3(0,0,1)
|
||||
|
||||
func play_full_plans():
|
||||
for player in players.values():
|
||||
|
|
|
@ -14,6 +14,8 @@ var weapons_plan : Plan = Plan.new()
|
|||
|
||||
var is_ready : bool = false
|
||||
var running_plan : bool = false
|
||||
var was_running_plan : bool = false
|
||||
var using_full_plan : bool = false
|
||||
var plan_time : float = 0.0
|
||||
|
||||
var health : float = 100.0
|
||||
|
@ -38,9 +40,10 @@ var end_linear_velocity : Vector3 = Vector3.ZERO
|
|||
var end_rotational_velocity : Vector3 = Vector3.ZERO
|
||||
var end_health : float = 100.0
|
||||
var end_energy : float = 100.0
|
||||
|
||||
var energy : float = 100.0
|
||||
|
||||
var players_in_firing_arc = []
|
||||
|
||||
func init():
|
||||
last_rotation = get_rotation()
|
||||
last_translation = get_translation()
|
||||
|
@ -114,13 +117,29 @@ func _get_all_weapons_elements():
|
|||
func _physics_process(delta : float) -> void:
|
||||
if !enable_physics:
|
||||
return
|
||||
|
||||
if !running_plan:
|
||||
if waiting_for_completion:
|
||||
send_all_plans()
|
||||
waiting_for_completion = false
|
||||
translation = last_translation
|
||||
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
|
||||
var all_thrust_elements = _get_all_thrust_elements()
|
||||
var current_thrust_element : ThrustElement = _get_current_plan_element(all_thrust_elements)
|
||||
if current_thrust_element == null:
|
||||
|
@ -147,10 +166,19 @@ func _physics_process(delta : float) -> void:
|
|||
plan_time += delta
|
||||
|
||||
func fire(delta : float, time : float) -> void:
|
||||
var closest_enemy = null
|
||||
var distance_of_closest = -1
|
||||
for player in players_in_firing_arc:
|
||||
if player.id == 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
|
||||
|
||||
energy -= delta * BASE_ENERGY_USAGE
|
||||
if $GunContainer/RayCast.is_colliding():
|
||||
var target : RigidBody = $GunContainer/RayCast.get_collider()
|
||||
target.take_damage(BASE_DPS * delta, time)
|
||||
if closest_enemy != null:
|
||||
closest_enemy.take_damage(BASE_DPS * delta, time)
|
||||
|
||||
func take_damage(damage : float, time : float) -> void:
|
||||
health -= damage
|
||||
|
@ -159,6 +187,7 @@ func take_damage(damage : float, time : float) -> void:
|
|||
|
||||
func die(time : float) -> void:
|
||||
is_alive = false
|
||||
$GunContainer/Cone.monitoring = false
|
||||
if !has_died:
|
||||
if report_death_to_arena():
|
||||
finish_game()
|
||||
|
@ -171,24 +200,20 @@ func play_all_plans():
|
|||
get_parent().play_full_plans()
|
||||
|
||||
func play_full_plan():
|
||||
set_linear_velocity(initial_velocity)
|
||||
set_angular_velocity(initial_rotational_velocity)
|
||||
set_translation(initial_translation)
|
||||
set_rotation(initial_rotation)
|
||||
using_full_plan = true
|
||||
running_plan = true
|
||||
plan_time = 0.0
|
||||
is_alive = true
|
||||
$GunContainer/Cone.monitoring = true
|
||||
$CollisionShape.disabled = false
|
||||
|
||||
func play_last_plan():
|
||||
set_linear_velocity(end_linear_velocity)
|
||||
set_angular_velocity(end_rotational_velocity)
|
||||
set_translation(end_translation)
|
||||
set_rotation(end_rotation)
|
||||
using_full_plan = false
|
||||
running_plan = true
|
||||
plan_time = 5 * turn_number
|
||||
if !has_died:
|
||||
is_alive = true
|
||||
$GunContainer/Cone.monitoring = true
|
||||
$CollisionShape.disabled = false
|
||||
|
||||
func calculate_plans():
|
||||
|
@ -209,3 +234,9 @@ func report_death_to_arena() -> bool:
|
|||
|
||||
func finish_game() -> void:
|
||||
get_parent().finish_game()
|
||||
|
||||
func _on_player_enter_firing_arc(body):
|
||||
players_in_firing_arc.append(body)
|
||||
|
||||
func _on_player_exit_firing_arc(body):
|
||||
players_in_firing_arc.erase(body)
|
||||
|
|
|
@ -44,6 +44,7 @@ config/icon="res://icon.png"
|
|||
|
||||
[physics]
|
||||
|
||||
3d/physics_engine="GodotPhysics"
|
||||
3d/default_gravity=0.0
|
||||
|
||||
[rendering]
|
||||
|
|
Loading…
Reference in New Issue