diff --git a/.import/Bottom_tank.dae-85bc63fa8a294f662e75e4a41fcd71ca.md5 b/.import/Bottom_tank.dae-85bc63fa8a294f662e75e4a41fcd71ca.md5 new file mode 100644 index 0000000..e9718bb --- /dev/null +++ b/.import/Bottom_tank.dae-85bc63fa8a294f662e75e4a41fcd71ca.md5 @@ -0,0 +1,3 @@ +source_md5="edf0227dc83d529ddc426be0b2307f74" +dest_md5="4317eabf26800407c4217e94f37f0a79" + diff --git a/.import/Bottom_tank.dae-85bc63fa8a294f662e75e4a41fcd71ca.scn b/.import/Bottom_tank.dae-85bc63fa8a294f662e75e4a41fcd71ca.scn new file mode 100644 index 0000000..fed5134 Binary files /dev/null and b/.import/Bottom_tank.dae-85bc63fa8a294f662e75e4a41fcd71ca.scn differ diff --git a/.import/Top_tank.dae-e1c50f41400079eb4488cd02f78a29c7.md5 b/.import/Top_tank.dae-e1c50f41400079eb4488cd02f78a29c7.md5 new file mode 100644 index 0000000..ca5af71 --- /dev/null +++ b/.import/Top_tank.dae-e1c50f41400079eb4488cd02f78a29c7.md5 @@ -0,0 +1,3 @@ +source_md5="9eab99d70ccd721911d0e95cb3dc0e6a" +dest_md5="be88d9e1f653c3a962dd7f787001613f" + diff --git a/.import/Top_tank.dae-e1c50f41400079eb4488cd02f78a29c7.scn b/.import/Top_tank.dae-e1c50f41400079eb4488cd02f78a29c7.scn new file mode 100644 index 0000000..cef5f3e Binary files /dev/null and b/.import/Top_tank.dae-e1c50f41400079eb4488cd02f78a29c7.scn differ diff --git a/.import/tank.dae-5a6d3732e687119983d41d9ebec878ed.md5 b/.import/tank.dae-5a6d3732e687119983d41d9ebec878ed.md5 new file mode 100644 index 0000000..036c2bb --- /dev/null +++ b/.import/tank.dae-5a6d3732e687119983d41d9ebec878ed.md5 @@ -0,0 +1,3 @@ +source_md5="d625b5879f6e5866b73469f9679decaf" +dest_md5="1951b3507ff7167a76d0d40074c3c646" + diff --git a/.import/tank.dae-5a6d3732e687119983d41d9ebec878ed.scn b/.import/tank.dae-5a6d3732e687119983d41d9ebec878ed.scn new file mode 100644 index 0000000..406ea9d Binary files /dev/null and b/.import/tank.dae-5a6d3732e687119983d41d9ebec878ed.scn differ diff --git a/Objects/Ai-tank/tank00.gd b/Objects/Ai-tank/tank00.gd index 7433d88..1943030 100644 --- a/Objects/Ai-tank/tank00.gd +++ b/Objects/Ai-tank/tank00.gd @@ -16,6 +16,7 @@ var ablewalk = 0 var speed = 10 var gravity = 100 var velocity = Vector3.ZERO +var angular_acceleration = 7 # How fast the tank rotates onready var player = get_node("/root/Spatial/PlayerTank") func _ready(): @@ -44,12 +45,13 @@ func _physics_process(delta): if ablewalk == 0: _walk_towards_player() _look_at_player() + $CollisionShapeBottom.rotation.y = lerp_angle($CollisionShapeBottom.rotation.y, atan2(velocity.x, velocity.z), delta * angular_acceleration) func _bullet_fire(): if player != null: var b = Bullet.instance() owner.add_child(b) - b.transform = $CollisionShape/Tank/BulletGenerator.global_transform + b.transform = $CollisionShapeTop/Top_tank/BulletGenerator.global_transform b.velocity = -b.global_transform.basis.z * b.muzzle_velocity bulletrandomnum.randomize() @@ -63,7 +65,7 @@ func _walk_towards_player(): func _look_at_player(): if player != null: - $CollisionShape.look_at(Vector3(player.global_transform.origin.x, global_transform.origin.y, player.global_transform.origin.z), Vector3(0,1,0)) # Look at player + $CollisionShapeTop.look_at(Vector3(player.global_transform.origin.x, global_transform.origin.y, player.global_transform.origin.z), Vector3(0,1,0)) # Look at player func _walk_towards_player_timer(): walkingrandomnum.randomize() diff --git a/Objects/Ai-tank/tank00.tscn b/Objects/Ai-tank/tank00.tscn index 19fa3f5..c559e68 100644 --- a/Objects/Ai-tank/tank00.tscn +++ b/Objects/Ai-tank/tank00.tscn @@ -1,24 +1,31 @@ -[gd_scene load_steps=5 format=2] +[gd_scene load_steps=6 format=2] [ext_resource path="res://Objects/Ai-tank/tank00.gd" type="Script" id=1] +[ext_resource path="res://Objects/Player-tank/model/Bottom_tank.dae" type="PackedScene" id=2] +[ext_resource path="res://Objects/Player-tank/model/Top_tank.dae" type="PackedScene" id=3] [sub_resource type="BoxShape" id=1] +extents = Vector3( 1.29, 1, 2.428 ) -[sub_resource type="CubeMesh" id=2] - -[sub_resource type="SpatialMaterial" id=3] -albedo_color = Color( 1, 0, 0, 1 ) +[sub_resource type="BoxShape" id=2] [node name="AITank00" type="KinematicBody"] script = ExtResource( 1 ) -[node name="CollisionShape" type="CollisionShape" parent="." groups=["tank"]] +[node name="CollisionShapeBottom" type="CollisionShape" parent="." groups=["player", "tank"]] shape = SubResource( 1 ) -[node name="Tank" type="MeshInstance" parent="CollisionShape" groups=["tank"]] -mesh = SubResource( 2 ) -skeleton = NodePath("../..") -material/0 = SubResource( 3 ) +[node name="Bottom_tank" parent="CollisionShapeBottom" instance=ExtResource( 2 )] +transform = Transform( -1.44248e-06, 0, 33, 0, 33, 0, -33, 0, -1.44248e-06, 0, -1.90625, 0 ) -[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 ) +[node name="CollisionShapeTop" type="CollisionShape" parent="."] +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.572825, 0 ) +shape = SubResource( 2 ) + +[node name="Top_tank" parent="CollisionShapeTop" instance=ExtResource( 3 )] +transform = Transform( -1.44248e-06, 0, 33, 0, 33, 0, -33, 0, -1.44248e-06, 0, -2.74403, 0 ) + +[node name="BulletGenerator" type="Position3D" parent="CollisionShapeTop/Top_tank"] +transform = Transform( -1.32459e-09, 0, -0.030303, 0, 0.030303, 0, 0.030303, 0, -1.32459e-09, 0.124162, 0.0831104, -9.97006e-05 ) + +[node name="TankAI" type="Node" parent="."] diff --git a/Objects/Bullet/Bullet.gd b/Objects/Bullet/Bullet.gd index 0c4dd9c..33094a7 100644 --- a/Objects/Bullet/Bullet.gd +++ b/Objects/Bullet/Bullet.gd @@ -2,7 +2,7 @@ extends Area signal exploded -export var muzzle_velocity = 25 +export var muzzle_velocity = 25 # How fast the bullets are export var g = Vector3.DOWN * 20 var velocity = Vector3.ZERO @@ -18,10 +18,12 @@ func _physics_process(delta): print ("Found Player Tank") self.queue_free() body.queue_free() - if get_overlapping_bodies().has(get_parent().get_node("AITank00")): - print ("Found AI Tank") - self.queue_free() - body.queue_free() + else: + if get_overlapping_bodies(): + if body.has_node("TankAI"): + print ("Found AI Tank") + self.queue_free() + body.queue_free() func _on_Shell_body_entered(body): diff --git a/Objects/Player-tank/Player.gd b/Objects/Player-tank/Player.gd index b3823d9..8af9507 100644 --- a/Objects/Player-tank/Player.gd +++ b/Objects/Player-tank/Player.gd @@ -6,6 +6,7 @@ var rayOrigin = Vector3() var rayEnd = Vector3() var speed = 15 var gravity = 100 +var angular_acceleration = 7 # How fast the player rotates var velocity = Vector3.ZERO func _physics_process(delta): @@ -33,12 +34,14 @@ func _physics_process(delta): var intersection = space_state.intersect_ray(rayOrigin, rayEnd) # Set variable for cursor position if not intersection.empty(): # Make sure there is a intersection with raycast var pos = intersection.position - $CollisionShapeTop.look_at(Vector3(pos.x, pos.y, pos.z), Vector3(0,1,0)) + $CollisionShapeTop.look_at(Vector3(pos.x, $CollisionShapeTop.translation.y, pos.z), Vector3(0,1,0)) if direction != Vector3.ZERO: direction = direction.normalized() # $Pivot.look_at(translation + direction, Vector3.UP) + $CollisionShapeBottom.rotation.y = lerp_angle($CollisionShapeBottom.rotation.y, atan2(direction.x, direction.z), delta * angular_acceleration) + velocity.x = direction.x * speed velocity.z = direction.z * speed velocity.y -= gravity * delta