WIP AI
This commit is contained in:
parent
75f19e9999
commit
98da26637d
7 changed files with 57 additions and 2 deletions
|
@ -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/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]
|
[sub_resource type="PlaneMesh" id=1]
|
||||||
|
|
||||||
|
@ -22,3 +23,6 @@ material/0 = null
|
||||||
[node name="CollisionShape" type="CollisionShape" parent="StaticBody"]
|
[node name="CollisionShape" type="CollisionShape" parent="StaticBody"]
|
||||||
transform = Transform( 1, 0, 0, 0, 0.0361063, 0, 0, 0, 1, 0, 0, 0 )
|
transform = Transform( 1, 0, 0, 0, 0.0361063, 0, 0, 0, 1, 0, 0, 0 )
|
||||||
shape = SubResource( 2 )
|
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 )
|
||||||
|
|
18
Objects/Ai-tank/tank00.gd
Normal file
18
Objects/Ai-tank/tank00.gd
Normal file
|
@ -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))
|
||||||
|
|
24
Objects/Ai-tank/tank00.tscn
Normal file
24
Objects/Ai-tank/tank00.tscn
Normal file
|
@ -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 )
|
|
@ -7,7 +7,7 @@
|
||||||
[sub_resource type="BoxShape" id=1]
|
[sub_resource type="BoxShape" id=1]
|
||||||
extents = Vector3( 0.20228, 0.203418, 0.196524 )
|
extents = Vector3( 0.20228, 0.203418, 0.196524 )
|
||||||
|
|
||||||
[node name="Bullet" type="Area"]
|
[node name="Bullet" type="Area" groups=["bullet"]]
|
||||||
script = ExtResource( 1 )
|
script = ExtResource( 1 )
|
||||||
|
|
||||||
[node name="MeshInstance" type="MeshInstance" parent="."]
|
[node name="MeshInstance" type="MeshInstance" parent="."]
|
||||||
|
|
|
@ -9,8 +9,10 @@ var gravity = 100
|
||||||
var velocity = Vector3.ZERO
|
var velocity = Vector3.ZERO
|
||||||
|
|
||||||
func _physics_process(delta):
|
func _physics_process(delta):
|
||||||
|
Global.player = self # Makes the player variable in the global script equal to self
|
||||||
var direction = Vector3.ZERO
|
var direction = Vector3.ZERO
|
||||||
|
|
||||||
|
### Input management
|
||||||
if Input.is_action_pressed("move_right"):
|
if Input.is_action_pressed("move_right"):
|
||||||
direction.x += 1
|
direction.x += 1
|
||||||
if Input.is_action_pressed("move_left"):
|
if Input.is_action_pressed("move_left"):
|
||||||
|
|
3
misc/scripts/global.gd
Normal file
3
misc/scripts/global.gd
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
extends Node
|
||||||
|
|
||||||
|
var player
|
|
@ -25,6 +25,10 @@ run/main_scene="res://Levels/Level01.tscn"
|
||||||
boot_splash/image="res://2D Art/Splash Screen/Tank Blaster Splash.png"
|
boot_splash/image="res://2D Art/Splash Screen/Tank Blaster Splash.png"
|
||||||
config/icon="res://icon.png"
|
config/icon="res://icon.png"
|
||||||
|
|
||||||
|
[autoload]
|
||||||
|
|
||||||
|
Global="*res://misc/scripts/global.gd"
|
||||||
|
|
||||||
[display]
|
[display]
|
||||||
|
|
||||||
window/size/width=1920
|
window/size/width=1920
|
||||||
|
|
Loading…
Reference in a new issue