Made tank turn with direction of velocity. Improved how a tank is considered AI for bullet checks.
This commit is contained in:
parent
5437b1c6f3
commit
09c44ca20b
10 changed files with 43 additions and 20 deletions
|
@ -0,0 +1,3 @@
|
||||||
|
source_md5="edf0227dc83d529ddc426be0b2307f74"
|
||||||
|
dest_md5="4317eabf26800407c4217e94f37f0a79"
|
||||||
|
|
BIN
.import/Bottom_tank.dae-85bc63fa8a294f662e75e4a41fcd71ca.scn
Normal file
BIN
.import/Bottom_tank.dae-85bc63fa8a294f662e75e4a41fcd71ca.scn
Normal file
Binary file not shown.
|
@ -0,0 +1,3 @@
|
||||||
|
source_md5="9eab99d70ccd721911d0e95cb3dc0e6a"
|
||||||
|
dest_md5="be88d9e1f653c3a962dd7f787001613f"
|
||||||
|
|
BIN
.import/Top_tank.dae-e1c50f41400079eb4488cd02f78a29c7.scn
Normal file
BIN
.import/Top_tank.dae-e1c50f41400079eb4488cd02f78a29c7.scn
Normal file
Binary file not shown.
3
.import/tank.dae-5a6d3732e687119983d41d9ebec878ed.md5
Normal file
3
.import/tank.dae-5a6d3732e687119983d41d9ebec878ed.md5
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
source_md5="d625b5879f6e5866b73469f9679decaf"
|
||||||
|
dest_md5="1951b3507ff7167a76d0d40074c3c646"
|
||||||
|
|
BIN
.import/tank.dae-5a6d3732e687119983d41d9ebec878ed.scn
Normal file
BIN
.import/tank.dae-5a6d3732e687119983d41d9ebec878ed.scn
Normal file
Binary file not shown.
|
@ -16,6 +16,7 @@ var ablewalk = 0
|
||||||
var speed = 10
|
var speed = 10
|
||||||
var gravity = 100
|
var gravity = 100
|
||||||
var velocity = Vector3.ZERO
|
var velocity = Vector3.ZERO
|
||||||
|
var angular_acceleration = 7 # How fast the tank rotates
|
||||||
onready var player = get_node("/root/Spatial/PlayerTank")
|
onready var player = get_node("/root/Spatial/PlayerTank")
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
|
@ -44,12 +45,13 @@ func _physics_process(delta):
|
||||||
if ablewalk == 0:
|
if ablewalk == 0:
|
||||||
_walk_towards_player()
|
_walk_towards_player()
|
||||||
_look_at_player()
|
_look_at_player()
|
||||||
|
$CollisionShapeBottom.rotation.y = lerp_angle($CollisionShapeBottom.rotation.y, atan2(velocity.x, velocity.z), delta * angular_acceleration)
|
||||||
|
|
||||||
func _bullet_fire():
|
func _bullet_fire():
|
||||||
if player != null:
|
if player != null:
|
||||||
var b = Bullet.instance()
|
var b = Bullet.instance()
|
||||||
owner.add_child(b)
|
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
|
b.velocity = -b.global_transform.basis.z * b.muzzle_velocity
|
||||||
|
|
||||||
bulletrandomnum.randomize()
|
bulletrandomnum.randomize()
|
||||||
|
@ -63,7 +65,7 @@ func _walk_towards_player():
|
||||||
|
|
||||||
func _look_at_player():
|
func _look_at_player():
|
||||||
if player != null:
|
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():
|
func _walk_towards_player_timer():
|
||||||
walkingrandomnum.randomize()
|
walkingrandomnum.randomize()
|
||||||
|
|
|
@ -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/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]
|
[sub_resource type="BoxShape" id=1]
|
||||||
|
extents = Vector3( 1.29, 1, 2.428 )
|
||||||
|
|
||||||
[sub_resource type="CubeMesh" id=2]
|
[sub_resource type="BoxShape" id=2]
|
||||||
|
|
||||||
[sub_resource type="SpatialMaterial" id=3]
|
|
||||||
albedo_color = Color( 1, 0, 0, 1 )
|
|
||||||
|
|
||||||
[node name="AITank00" type="KinematicBody"]
|
[node name="AITank00" type="KinematicBody"]
|
||||||
script = ExtResource( 1 )
|
script = ExtResource( 1 )
|
||||||
|
|
||||||
[node name="CollisionShape" type="CollisionShape" parent="." groups=["tank"]]
|
[node name="CollisionShapeBottom" type="CollisionShape" parent="." groups=["player", "tank"]]
|
||||||
shape = SubResource( 1 )
|
shape = SubResource( 1 )
|
||||||
|
|
||||||
[node name="Tank" type="MeshInstance" parent="CollisionShape" groups=["tank"]]
|
[node name="Bottom_tank" parent="CollisionShapeBottom" instance=ExtResource( 2 )]
|
||||||
mesh = SubResource( 2 )
|
transform = Transform( -1.44248e-06, 0, 33, 0, 33, 0, -33, 0, -1.44248e-06, 0, -1.90625, 0 )
|
||||||
skeleton = NodePath("../..")
|
|
||||||
material/0 = SubResource( 3 )
|
|
||||||
|
|
||||||
[node name="BulletGenerator" type="Position3D" parent="CollisionShape/Tank"]
|
[node name="CollisionShapeTop" type="CollisionShape" parent="."]
|
||||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -0.0032903, 0.375606, -1.3599 )
|
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="."]
|
||||||
|
|
|
@ -2,7 +2,7 @@ extends Area
|
||||||
|
|
||||||
signal exploded
|
signal exploded
|
||||||
|
|
||||||
export var muzzle_velocity = 25
|
export var muzzle_velocity = 25 # How fast the bullets are
|
||||||
export var g = Vector3.DOWN * 20
|
export var g = Vector3.DOWN * 20
|
||||||
|
|
||||||
var velocity = Vector3.ZERO
|
var velocity = Vector3.ZERO
|
||||||
|
@ -18,10 +18,12 @@ func _physics_process(delta):
|
||||||
print ("Found Player Tank")
|
print ("Found Player Tank")
|
||||||
self.queue_free()
|
self.queue_free()
|
||||||
body.queue_free()
|
body.queue_free()
|
||||||
if get_overlapping_bodies().has(get_parent().get_node("AITank00")):
|
else:
|
||||||
print ("Found AI Tank")
|
if get_overlapping_bodies():
|
||||||
self.queue_free()
|
if body.has_node("TankAI"):
|
||||||
body.queue_free()
|
print ("Found AI Tank")
|
||||||
|
self.queue_free()
|
||||||
|
body.queue_free()
|
||||||
|
|
||||||
|
|
||||||
func _on_Shell_body_entered(body):
|
func _on_Shell_body_entered(body):
|
||||||
|
|
|
@ -6,6 +6,7 @@ var rayOrigin = Vector3()
|
||||||
var rayEnd = Vector3()
|
var rayEnd = Vector3()
|
||||||
var speed = 15
|
var speed = 15
|
||||||
var gravity = 100
|
var gravity = 100
|
||||||
|
var angular_acceleration = 7 # How fast the player rotates
|
||||||
var velocity = Vector3.ZERO
|
var velocity = Vector3.ZERO
|
||||||
|
|
||||||
func _physics_process(delta):
|
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
|
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
|
if not intersection.empty(): # Make sure there is a intersection with raycast
|
||||||
var pos = intersection.position
|
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:
|
if direction != Vector3.ZERO:
|
||||||
direction = direction.normalized()
|
direction = direction.normalized()
|
||||||
# $Pivot.look_at(translation + direction, Vector3.UP)
|
# $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.x = direction.x * speed
|
||||||
velocity.z = direction.z * speed
|
velocity.z = direction.z * speed
|
||||||
velocity.y -= gravity * delta
|
velocity.y -= gravity * delta
|
||||||
|
|
Loading…
Reference in a new issue