AI, bullets do damage, etc.
This commit is contained in:
parent
7ffed59347
commit
f224c93c93
13 changed files with 129 additions and 47 deletions
|
@ -8,8 +8,8 @@ const JUMP_VELOCITY = 4.5
|
|||
var gravity = ProjectSettings.get_setting("physics/3d/default_gravity")
|
||||
|
||||
@export var Bullet = preload("res://objects/Bullet/Bullet.tscn")
|
||||
@onready var neck := $Neck
|
||||
@onready var camera := $Neck/Camera3D
|
||||
@onready var neck := $CollisionShape3D/Neck
|
||||
@onready var camera := $CollisionShape3D/Neck/Camera3D
|
||||
|
||||
var globalscene
|
||||
|
||||
|
@ -50,13 +50,11 @@ func _physics_process(delta):
|
|||
position.x = 0 #Set player X
|
||||
position.y = 1 #Set player Y
|
||||
position.z = 0 #Set player Z
|
||||
Global.playerPleaseRespawn = false # So we don't get stuck in a loop
|
||||
Global.playerDead = false #Reset playerDead
|
||||
Global.playerAlive = true #Reset playerAlive
|
||||
Global.reset_variables()
|
||||
|
||||
## If player falls off the map, kill them!
|
||||
if velocity.y < Global.playerYDeath:
|
||||
Global.player_dead()
|
||||
Global.playerHealth = 0
|
||||
if Global.playerHealth <= 0:
|
||||
Global.player_dead()
|
||||
|
||||
|
@ -92,7 +90,7 @@ func _physics_process(delta):
|
|||
print("shoot")
|
||||
var b = Bullet.instantiate()
|
||||
owner.add_child(b)
|
||||
b.transform = $Neck/BulletGenerator.global_transform
|
||||
b.transform = $CollisionShape3D/Neck/BulletGenerator.global_transform
|
||||
b.velocity = -b.global_transform.basis.z * b.muzzle_velocity
|
||||
if Input.is_action_just_pressed("console"):
|
||||
var scene_trs = load("res://scenes/console.tscn")
|
||||
|
|
|
@ -17,33 +17,17 @@ func _physics_process(delta):
|
|||
transform.origin += velocity * delta
|
||||
|
||||
for body in get_overlapping_bodies(): ### THIS IS OLD LOGIC, REPLACE. I'D RECOMMEND TO CHECK BY GROUP AND NOT BY NODE
|
||||
if get_overlapping_bodies().has(get_parent().get_node(^"PlayerTank")):
|
||||
print ("Found Player Tank")
|
||||
if body.is_in_group("human"):
|
||||
print("Bullet hit a human player")
|
||||
Global.playerHealth = Global.playerHealth - 10
|
||||
self.queue_free()
|
||||
if body.is_in_group("AI"):
|
||||
print("Bullet hit an AI player")
|
||||
body.queue_free()
|
||||
self.queue_free()
|
||||
if (godmode == 0):
|
||||
body.queue_free()
|
||||
Global.playerdead = 1
|
||||
Global.tankskilled = 0
|
||||
Global.beforedeathscene = get_tree().current_scene.filename
|
||||
get_tree().change_scene("res://Levels/Dead.tscn")
|
||||
else:
|
||||
if get_overlapping_bodies():
|
||||
if body.has_node("TankAI"):
|
||||
print ("Found AI Tank")
|
||||
Global.tankskilled = Global.tankskilled + 1
|
||||
if (Global.tankskilled == 10):
|
||||
if (Global.firstlevelcompleted == 0):
|
||||
Global.firstlevelcompleted = 1
|
||||
get_tree().change_scene("res://Levels/win-01.tscn")
|
||||
else:
|
||||
if (Global.firstlevelcompleted == 1):
|
||||
get_tree().change_scene("res://Levels/Win-02.tscn")
|
||||
Global.tankskilled = 0
|
||||
self.queue_free()
|
||||
body.queue_free()
|
||||
else:
|
||||
print ("Bullet Collided with something else")
|
||||
self.queue_free()
|
||||
print("Bullet hit something else")
|
||||
self.queue_free()
|
||||
|
||||
|
||||
func _on_Shell_body_entered(body):
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
[ext_resource type="Script" path="res://objects/Bullet/Bullet.gd" id="1"]
|
||||
[ext_resource type="PackedScene" uid="uid://pni78bumc5f5" path="res://objects/Bullet/model/Bullet.dae" id="2"]
|
||||
|
||||
[sub_resource type="BoxShape3D" id="BoxShape3D_rite6"]
|
||||
[sub_resource type="BoxShape3D" id="BoxShape3D_h2x0g"]
|
||||
size = Vector3(0.40456, 0.406836, 0.393048)
|
||||
|
||||
[node name="Bullet" type="Area3D" groups=["bullet"]]
|
||||
|
@ -12,7 +12,7 @@ script = ExtResource("1")
|
|||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="." groups=["bullet"]]
|
||||
transform = Transform3D(0.957696, 0, 0, 0, 1, 0, 0, 0, 1.66763, 0, 0, -0.295843)
|
||||
shape = SubResource("BoxShape3D_rite6")
|
||||
shape = SubResource("BoxShape3D_h2x0g")
|
||||
|
||||
[node name="Bullet" parent="." instance=ExtResource("2")]
|
||||
transform = Transform3D(0.200224, 0, 0, 0, -8.75207e-09, 0.200224, 0, -0.200224, -8.75207e-09, 0, 0, 0)
|
||||
|
|
24
scenes/AI.tscn
Normal file
24
scenes/AI.tscn
Normal file
|
@ -0,0 +1,24 @@
|
|||
[gd_scene load_steps=4 format=3 uid="uid://y3fffh5cdbks"]
|
||||
|
||||
[ext_resource type="Script" path="res://scripts/AI.gd" id="1_1d27o"]
|
||||
|
||||
[sub_resource type="BoxShape3D" id="BoxShape3D_7vhwh"]
|
||||
size = Vector3(1, 1.99126, 1)
|
||||
|
||||
[sub_resource type="CapsuleMesh" id="CapsuleMesh_ucocb"]
|
||||
|
||||
[node name="AI" type="CharacterBody3D" groups=["AI"]]
|
||||
script = ExtResource("1_1d27o")
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
|
||||
shape = SubResource("BoxShape3D_7vhwh")
|
||||
|
||||
[node name="Neck" type="Node3D" parent="CollisionShape3D"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.859224, 0)
|
||||
|
||||
[node name="BulletGenerator" type="Marker3D" parent="CollisionShape3D/Neck"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.104801, -0.858231)
|
||||
|
||||
[node name="MeshInstance3D" type="MeshInstance3D" parent="CollisionShape3D"]
|
||||
mesh = SubResource("CapsuleMesh_ucocb")
|
||||
skeleton = NodePath("")
|
|
@ -1,25 +1,37 @@
|
|||
[gd_scene load_steps=4 format=3 uid="uid://dp1q51kvd8uow"]
|
||||
[gd_scene load_steps=5 format=3 uid="uid://dp1q51kvd8uow"]
|
||||
|
||||
[ext_resource type="Script" path="res://characters/teddy/Teddy.gd" id="1_ywxo5"]
|
||||
|
||||
[sub_resource type="CapsuleMesh" id="CapsuleMesh_qq44a"]
|
||||
|
||||
[sub_resource type="BoxShape3D" id="BoxShape3D_rpt2n"]
|
||||
size = Vector3(1, 1.99126, 1)
|
||||
|
||||
[node name="Teddy" type="CharacterBody3D"]
|
||||
script = ExtResource("1_ywxo5")
|
||||
[sub_resource type="CapsuleMesh" id="CapsuleMesh_qq44a"]
|
||||
|
||||
[node name="MeshInstance3D" type="MeshInstance3D" parent="."]
|
||||
mesh = SubResource("CapsuleMesh_qq44a")
|
||||
[sub_resource type="SceneReplicationConfig" id="SceneReplicationConfig_6xwyk"]
|
||||
properties/0/path = NodePath(".:position")
|
||||
properties/0/spawn = true
|
||||
properties/0/sync = true
|
||||
properties/1/path = NodePath(".:rotation")
|
||||
properties/1/spawn = true
|
||||
properties/1/sync = true
|
||||
|
||||
[node name="Teddy" type="CharacterBody3D" groups=["human"]]
|
||||
script = ExtResource("1_ywxo5")
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
|
||||
shape = SubResource("BoxShape3D_rpt2n")
|
||||
|
||||
[node name="Neck" type="Node3D" parent="."]
|
||||
[node name="MeshInstance3D" type="MeshInstance3D" parent="CollisionShape3D"]
|
||||
mesh = SubResource("CapsuleMesh_qq44a")
|
||||
skeleton = NodePath("../..")
|
||||
|
||||
[node name="Neck" type="Node3D" parent="CollisionShape3D"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.859224, 0)
|
||||
|
||||
[node name="Camera3D" type="Camera3D" parent="Neck"]
|
||||
[node name="Camera3D" type="Camera3D" parent="CollisionShape3D/Neck"]
|
||||
|
||||
[node name="BulletGenerator" type="Marker3D" parent="Neck"]
|
||||
[node name="BulletGenerator" type="Marker3D" parent="CollisionShape3D/Neck"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.104801, -0.858231)
|
||||
|
||||
[node name="MultiplayerSynchronizer" type="MultiplayerSynchronizer" parent="."]
|
||||
replication_config = SubResource("SceneReplicationConfig_6xwyk")
|
||||
|
|
|
@ -106,6 +106,7 @@ scale = Vector2(0.194581, 0.194581)
|
|||
texture = ExtResource("2_0dbbk")
|
||||
|
||||
[node name="Button" type="Button" parent="."]
|
||||
layout_mode = 0
|
||||
offset_left = 380.0
|
||||
offset_top = 136.0
|
||||
offset_right = 411.0
|
||||
|
|
9
scenes/multiplayer-spawner.tscn
Normal file
9
scenes/multiplayer-spawner.tscn
Normal file
|
@ -0,0 +1,9 @@
|
|||
[gd_scene format=3 uid="uid://pq1wxt873twr"]
|
||||
|
||||
[node name="multiplayer-spawner" type="Node3D"]
|
||||
|
||||
[node name="Network" type="Node" parent="."]
|
||||
|
||||
[node name="MultiplayerSpawner" type="MultiplayerSpawner" parent="."]
|
||||
_spawnable_scenes = PackedStringArray("res://scenes/Teddy.tscn")
|
||||
spawn_path = NodePath("../Network")
|
|
@ -48,6 +48,7 @@ offset_bottom = 379.0
|
|||
text = "Yes"
|
||||
|
||||
[node name="noButton" type="Button" parent="."]
|
||||
layout_mode = 0
|
||||
offset_left = 597.0
|
||||
offset_top = 338.0
|
||||
offset_right = 691.0
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
[gd_scene load_steps=9 format=3 uid="uid://dkokyp5lwhks4"]
|
||||
[gd_scene load_steps=10 format=3 uid="uid://dkokyp5lwhks4"]
|
||||
|
||||
[ext_resource type="Script" path="res://scripts/maps/tutorial.gd" id="1_40ws8"]
|
||||
[ext_resource type="PackedScene" uid="uid://dp1q51kvd8uow" path="res://scenes/Teddy.tscn" id="1_081si"]
|
||||
[ext_resource type="PackedScene" uid="uid://ytbacsuahxie" path="res://scenes/HUD.tscn" id="2_s3v8n"]
|
||||
[ext_resource type="PackedScene" uid="uid://y3fffh5cdbks" path="res://scenes/AI.tscn" id="4_fttoe"]
|
||||
|
||||
[sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_i5hsu"]
|
||||
sky_top_color = Color(1, 1, 1, 1)
|
||||
|
@ -46,3 +47,6 @@ shape = SubResource("ConcavePolygonShape3D_hllao")
|
|||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 2.08165e-12, 1.039, 2.08165e-12)
|
||||
|
||||
[node name="HUD" parent="." instance=ExtResource("2_s3v8n")]
|
||||
|
||||
[node name="AI" parent="." instance=ExtResource("4_fttoe")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -4.27149, 1.04845, -4.64617)
|
||||
|
|
37
scripts/AI.gd
Normal file
37
scripts/AI.gd
Normal file
|
@ -0,0 +1,37 @@
|
|||
extends CharacterBody3D
|
||||
|
||||
|
||||
const SPEED = 1.0
|
||||
const JUMP_VELOCITY = 4.5
|
||||
|
||||
var bullettimer = 50
|
||||
var bulletshot = false
|
||||
var bulletrandom
|
||||
|
||||
# Get the gravity from the project settings to be synced with RigidBody nodes.
|
||||
var gravity = ProjectSettings.get_setting("physics/3d/default_gravity")
|
||||
|
||||
@onready var player = get_node(^"/root/tutorial/Teddy")
|
||||
@export var Bullet = preload("res://objects/Bullet/Bullet.tscn")
|
||||
|
||||
func _physics_process(delta):
|
||||
# Add the gravity.
|
||||
if not is_on_floor():
|
||||
velocity.y -= gravity * delta
|
||||
|
||||
|
||||
if player and Global.playerAlive:
|
||||
bullettimer = bullettimer - 10 * delta
|
||||
if bullettimer < 0 and bulletshot == false:
|
||||
bulletshot = true
|
||||
var b = Bullet.instantiate()
|
||||
owner.add_child(b)
|
||||
b.transform = $CollisionShape3D/Neck/BulletGenerator.global_transform
|
||||
b.velocity = -b.global_transform.basis.z * b.muzzle_velocity
|
||||
elif bulletshot == true:
|
||||
bulletshot = false
|
||||
bulletrandom = randf_range(1.0, 50.0)
|
||||
bullettimer = bulletrandom
|
||||
velocity = (player.transform.origin - transform.origin).normalized() * SPEED
|
||||
$CollisionShape3D.look_at(Vector3(player.global_transform.origin.x, global_transform.origin.y, player.global_transform.origin.z), Vector3(0,1,0))
|
||||
move_and_slide()
|
|
@ -38,6 +38,12 @@ func run_command(command):
|
|||
Global.consoleOutput = "Yuppp that's me"
|
||||
elif command == "jayden":
|
||||
Global.consoleOutput = "That's the noob artist"
|
||||
elif command == "resetvars":
|
||||
Global.consoleOutput = "Reset variables"
|
||||
Global.reset_variables()
|
||||
elif command in ["suicide", "kill", "die"]:
|
||||
Global.consoleOutput = "Oh you didn't want to die?"
|
||||
Global.playerHealth = 0
|
||||
else:
|
||||
Global.consoleOutput = "Unknown cheat code"
|
||||
$output.text = Global.consoleOutput
|
||||
|
|
|
@ -17,7 +17,6 @@ var consoleOutput # Defined by console.gd
|
|||
var godMode = false # Defined by console.gd
|
||||
|
||||
func _process(delta):
|
||||
playerHealth = playerHealth - 20 * delta
|
||||
if godMode:
|
||||
pass
|
||||
elif Input.is_action_pressed("sprint"):
|
||||
|
@ -38,3 +37,11 @@ func player_dead():
|
|||
var scene_trs =load("res://scenes/death.tscn")
|
||||
var scene=scene_trs.instantiate()
|
||||
add_child(scene)
|
||||
|
||||
func reset_variables():
|
||||
print("Variables were reset by something")
|
||||
fatigue = 100
|
||||
playerHealth = 100
|
||||
playerDead = false
|
||||
playerAlive = true
|
||||
playerPleaseRespawn = false
|
||||
|
|
|
@ -7,7 +7,6 @@ func _ready():
|
|||
$Button.text = "RESUME"
|
||||
$Button4.text = "MAIN MENU"
|
||||
|
||||
|
||||
func _process(delta):
|
||||
pass
|
||||
|
||||
|
|
Loading…
Reference in a new issue