-
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Part 3 - Enemy tank: pathfollowing and aiming
- Loading branch information
Chris Bradfield
committed
Apr 5, 2018
1 parent
5936b57
commit 6aa4ed6
Showing
4 changed files
with
134 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
extends "res://tanks/Tank.gd" | ||
|
||
onready var parent = get_parent() | ||
|
||
export (float) var turret_speed | ||
export (int) var detect_radius | ||
|
||
var target = null | ||
|
||
func _ready(): | ||
$DetectRadius/CollisionShape2D.shape.radius = detect_radius | ||
|
||
func control(delta): | ||
if parent is PathFollow2D: | ||
parent.set_offset(parent.get_offset() + speed * delta) | ||
position = Vector2() | ||
else: | ||
# other movement code | ||
pass | ||
|
||
func _process(delta): | ||
if target: | ||
var target_dir = (target.global_position - global_position).normalized() | ||
var current_dir = Vector2(1, 0).rotated($Turret.global_rotation) | ||
$Turret.global_rotation = current_dir.linear_interpolate(target_dir, turret_speed * delta).angle() | ||
|
||
func _on_DetectRadius_body_entered(body): | ||
if body.name == "Player": | ||
target = body | ||
|
||
func _on_DetectRadius_body_exited(body): | ||
if body == target: | ||
target = null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
[gd_scene load_steps=6 format=2] | ||
|
||
[ext_resource path="res://tanks/Tank.tscn" type="PackedScene" id=1] | ||
[ext_resource path="res://tanks/EnemyTank.gd" type="Script" id=2] | ||
[ext_resource path="res://assets/onlyObjects_retina_rotated.png" type="Texture" id=3] | ||
|
||
[sub_resource type="RectangleShape2D" id=1] | ||
|
||
custom_solver_bias = 0.0 | ||
extents = Vector2( 39.7858, 35.5505 ) | ||
|
||
[sub_resource type="CircleShape2D" id=2] | ||
|
||
custom_solver_bias = 0.0 | ||
radius = 350.571 | ||
|
||
[node name="EnemyTank" instance=ExtResource( 1 )] | ||
|
||
script = ExtResource( 2 ) | ||
Bullet = null | ||
speed = 150 | ||
rotation_speed = null | ||
gun_cooldown = 0.5 | ||
health = 100 | ||
turret_speed = 1.0 | ||
detect_radius = 200 | ||
|
||
[node name="Body" parent="." index="0"] | ||
|
||
texture = ExtResource( 3 ) | ||
region_enabled = true | ||
region_rect = Rect2( 268, 186, 80, 76 ) | ||
_sections_unfolded = [ "Region" ] | ||
|
||
[node name="CollisionShape2D" parent="." index="1"] | ||
|
||
visible = false | ||
shape = SubResource( 1 ) | ||
|
||
[node name="Turret" parent="." index="2"] | ||
|
||
texture = ExtResource( 3 ) | ||
offset = Vector2( 20, 0 ) | ||
region_enabled = true | ||
region_rect = Rect2( 371, 14, 60, 24 ) | ||
_sections_unfolded = [ "Offset", "Region", "Transform" ] | ||
|
||
[node name="DetectRadius" type="Area2D" parent="." index="4"] | ||
|
||
input_pickable = true | ||
gravity_vec = Vector2( 0, 1 ) | ||
gravity = 98.0 | ||
linear_damp = 0.1 | ||
angular_damp = 1.0 | ||
audio_bus_override = false | ||
audio_bus_name = "Master" | ||
|
||
[node name="CollisionShape2D" type="CollisionShape2D" parent="DetectRadius" index="0"] | ||
|
||
shape = SubResource( 2 ) | ||
|
||
[connection signal="body_entered" from="DetectRadius" to="." method="_on_DetectRadius_body_entered"] | ||
|
||
[connection signal="body_exited" from="DetectRadius" to="." method="_on_DetectRadius_body_exited"] | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters