diff --git a/Levels/Level01.tscn b/Levels/Level01.tscn index 4ad1e92..b44f73c 100644 --- a/Levels/Level01.tscn +++ b/Levels/Level01.tscn @@ -1,6 +1,7 @@ -[gd_scene load_steps=4 format=2] +[gd_scene load_steps=5 format=2] [ext_resource path="res://Objects/Player-tank/player.tscn" type="PackedScene" id=1] +[ext_resource path="res://Objects/Ai-tank/tank00.tscn" type="PackedScene" id=2] [sub_resource type="PlaneMesh" id=1] @@ -22,3 +23,6 @@ material/0 = null [node name="CollisionShape" type="CollisionShape" parent="StaticBody"] transform = Transform( 1, 0, 0, 0, 0.0361063, 0, 0, 0, 1, 0, 0, 0 ) shape = SubResource( 2 ) + +[node name="AITank00" parent="." instance=ExtResource( 2 )] +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -12.2314, 1.17676, 14.9248 ) diff --git a/Objects/Ai-tank/tank00.gd b/Objects/Ai-tank/tank00.gd new file mode 100644 index 0000000..17311b1 --- /dev/null +++ b/Objects/Ai-tank/tank00.gd @@ -0,0 +1,18 @@ +extends KinematicBody + +var speed = 15 +var gravity = 100 +var velocity = Vector3.ZERO +onready var player = find_node("PlayerTank") ## FIXME + +func _physics_process(delta): + var direction = Vector3.ZERO + + velocity.x = direction.x * speed + velocity.z = direction.z * speed + velocity.y -= gravity * delta + velocity = move_and_slide(velocity, Vector3.UP) + + if player != null: # Makes sure player is not an empty variable (not equal to nill/null) + look_at(Vector3(player.global_transform.origin.x, global_transform.origin.y, player.global_transform.origin.z), Vector3(0,1,0)) + diff --git a/Objects/Ai-tank/tank00.tscn b/Objects/Ai-tank/tank00.tscn new file mode 100644 index 0000000..4b889ff --- /dev/null +++ b/Objects/Ai-tank/tank00.tscn @@ -0,0 +1,24 @@ +[gd_scene load_steps=5 format=2] + +[ext_resource path="res://Objects/Ai-tank/tank00.gd" type="Script" id=1] + +[sub_resource type="BoxShape" id=1] + +[sub_resource type="CubeMesh" id=2] + +[sub_resource type="SpatialMaterial" id=3] +albedo_color = Color( 1, 0, 0, 1 ) + +[node name="AITank00" type="KinematicBody"] +script = ExtResource( 1 ) + +[node name="CollisionShape" type="CollisionShape" parent="."] +shape = SubResource( 1 ) + +[node name="Tank" type="MeshInstance" parent="CollisionShape"] +mesh = SubResource( 2 ) +skeleton = NodePath("../..") +material/0 = SubResource( 3 ) + +[node name="BulletGenerator" type="Position3D" parent="CollisionShape/Tank"] +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -0.0032903, 0.375606, -1.3599 ) diff --git a/Objects/Bullet/Bullet.tscn b/Objects/Bullet/Bullet.tscn index affdcd3..55208c6 100644 --- a/Objects/Bullet/Bullet.tscn +++ b/Objects/Bullet/Bullet.tscn @@ -7,7 +7,7 @@ [sub_resource type="BoxShape" id=1] extents = Vector3( 0.20228, 0.203418, 0.196524 ) -[node name="Bullet" type="Area"] +[node name="Bullet" type="Area" groups=["bullet"]] script = ExtResource( 1 ) [node name="MeshInstance" type="MeshInstance" parent="."] diff --git a/Objects/Player-tank/Player.gd b/Objects/Player-tank/Player.gd index 75a551a..f869d0d 100644 --- a/Objects/Player-tank/Player.gd +++ b/Objects/Player-tank/Player.gd @@ -9,8 +9,10 @@ var gravity = 100 var velocity = Vector3.ZERO func _physics_process(delta): + Global.player = self # Makes the player variable in the global script equal to self var direction = Vector3.ZERO + ### Input management if Input.is_action_pressed("move_right"): direction.x += 1 if Input.is_action_pressed("move_left"): diff --git a/misc/scripts/global.gd b/misc/scripts/global.gd new file mode 100644 index 0000000..732995f --- /dev/null +++ b/misc/scripts/global.gd @@ -0,0 +1,3 @@ +extends Node + +var player diff --git a/project.godot b/project.godot index 12c291d..5553325 100644 --- a/project.godot +++ b/project.godot @@ -25,6 +25,10 @@ run/main_scene="res://Levels/Level01.tscn" boot_splash/image="res://2D Art/Splash Screen/Tank Blaster Splash.png" config/icon="res://icon.png" +[autoload] + +Global="*res://misc/scripts/global.gd" + [display] window/size/width=1920