Turret Vision

Implemented the turret vision area to successfully detect missiles and railgun targets (via node groups) and keep track of those that entered.
main
Peery 8 months ago
parent 4068d504a5
commit 0a2f7b30db

@ -2,14 +2,34 @@ extends Area
onready var turret_main = get_node("../../../../")
var allowed_groups = ["missile", "railgun_target"];
var seen_nodes = []
func body_entered(body: Node):
print(body.name+" just entered the vision!")
seen_nodes.append(body)
func body_exited(body: Node):
seen_nodes.remove(body)
func _body_entered(body: Node):
var proceed = false;
for allowed_group in allowed_groups:
if body.is_in_group(allowed_group):
proceed = true;
break;
if not proceed:
return;
print(body.get_parent().name+" just entered the vision!");
seen_nodes.append(body);
func _body_exited(body: Node):
var proceed = false;
for allowed_group in allowed_groups:
if body.is_in_group(allowed_group):
proceed = true;
break;
if not proceed:
return;
print(body.get_parent().name+" just left the vision!");
seen_nodes.remove(self.seen_nodes.find(body));
func _ready():
pass
print("TurretVision online!");
connect('body_entered', self, '_body_entered');
connect('body_exited', self, '_body_exited');

@ -11,7 +11,7 @@ var MISSILE_ID = "UNKNOWN";
var is_operational: bool = true; # if the missile is operational
var has_fuel: bool = true;
var turn_instruction: Vector3 = Vector3(0, 1, 0); # vector of (X, Y, Z) possible rotational thrust to apply (0.0 to 1.0 for full turn)
var turn_instruction: Vector3 = Vector3(0, 0, 0); # vector of (X, Y, Z) possible rotational thrust to apply (0.0 to 1.0 for full turn)
var thrust_instruction: float = 0.5; # throttle between 0.0 and 1.0 of available thrust to apply
var curr_rotation_vel: Vector3 = Vector3();
@ -27,11 +27,11 @@ func _set_thruster_thrust(node: MeshInstance, power):
if node.name in __curr_shader_param_cache:
if __curr_shader_param_cache[node.name] == power:
#print("Skipped shader edit");
return;
pass;#return;
### DEBUG CODE
if node.name in __curr_shader_param_cache:
print("Editing "+node.name+" because "+str(__curr_shader_param_cache[node.name])+" != "+str(power)+" (old vs new)");
#if node.name in __curr_shader_param_cache:
#print("Editing "+node.name+" because "+str(__curr_shader_param_cache[node.name])+" != "+str(power)+" (old vs new)");
###
__curr_shader_param_cache[node.name] = power;
@ -120,7 +120,7 @@ func _physics_process(delta):
if timer <= 0.0:
set_main_engine_thrust(0.0);
set_X_rotational_thrust(0.0);
set_Y_rotational_thrust(0.0); # TODO fix issue with turning off rotational thrusters
set_Y_rotational_thrust(0.0);
timer = 1.0
else:
@ -129,14 +129,13 @@ func _physics_process(delta):
set_Y_rotational_thrust(lerp(0.0, 10.0, turn_instruction.y));
set_main_engine_thrust(lerp(0.0, 10.0, thrust_instruction));
self.transform = self.transform.orthonormalized();
### DEBUG CODE
print("Rotation: "+str(self.curr_rotation_vel)+", Velocity: "+str(self.curr_velocity)+" Remeining dV: "+str(self.curr_DV));
#print("Rotation: "+str(self.curr_rotation_vel)+", Velocity: "+str(self.curr_velocity)+" Remeining dV: "+str(self.curr_DV));
###
timer = 1.0;
self.curr_rotation_vel += turn_instruction * Vector3(MAX_TURN_RATE, MAX_TURN_RATE, 0.0) * delta;
self.curr_rotation_vel += turn_instruction * Vector3(MAX_TURN_RATE, MAX_TURN_RATE, MAX_TURN_RATE) * delta;
self.curr_thrust = thrust_instruction * ACCEL * delta;
self.curr_velocity += self.global_transform.basis.z * self.curr_thrust * -1;
self.curr_DV -= curr_thrust;
@ -149,6 +148,7 @@ func _physics_process(delta):
if self.curr_rotation_vel.length() > 0.0:
self.rotate_x(deg2rad(self.curr_rotation_vel.x));
self.rotate_y(deg2rad(self.curr_rotation_vel.y));
self.rotate_z(deg2rad(self.curr_rotation_vel.z));
if self.curr_velocity.length() > 0.0:
#self.translate(self.curr_velocity);
self.global_translate(self.curr_velocity);

@ -115,14 +115,14 @@ shader = ExtResource( 4 )
shader_param/ANIM_SPEED = 100.0
shader_param/power = 1.0
[node name="missile" instance=ExtResource( 1 )]
[node name="missile" groups=["missile", "railgun_target"] instance=ExtResource( 1 )]
script = ExtResource( 3 )
[node name="missile body" parent="." index="0"]
transform = Transform( -1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, 0, 0, -0.851097 )
material/0 = SubResource( 2 )
[node name="RigidBody" type="RigidBody" parent="." index="1"]
[node name="RigidBody" type="RigidBody" parent="." index="1" groups=["missile"]]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -1.71819 )
[node name="CollisionShape" type="CollisionShape" parent="RigidBody" index="0"]

@ -49,16 +49,6 @@ func _ready():
func _process(delta):
# Calculating the two points where the vertical joint should point to to aim at the target
"""
var T = target.transform.origin
var C = skeleton.get_bone_global_pose(turret_pitch_bone).origin # Vector3 root of the pitch bone
var radius_C = (skeleton.get_bone_global_pose(turret_yaw_bone).origin - C).length()
var normal_C = (T-C).normalized()
var normal_C_angle = acos(Vector3(0, normal_C.y, normal_C.z).dot(normal_C)) # to transform the T point into a 2D plane and THEN do 2D circle intersection
var radius_T = (T - C).length() # length of CT which will be the radius of the circle around T"""
if first_call:
first_call = false
if target == null:

@ -54,6 +54,7 @@ mesh = SubResource( 2 )
skin = SubResource( 3 )
[node name="TurretVision" type="Area" parent="Armature/Skeleton/turretAttachement" index="2"]
monitorable = false
script = ExtResource( 3 )
[node name="CollisionShape" type="CollisionShape" parent="Armature/Skeleton/turretAttachement/TurretVision" index="0"]

Loading…
Cancel
Save