AI Bullets

This commit is contained in:
Paul Black 2023-03-19 16:28:17 -06:00
parent 4e694e55ef
commit adf1996cf0
8 changed files with 233 additions and 6 deletions

View file

@ -0,0 +1,37 @@
extends Area3D
signal exploded
@export var muzzle_velocity = 100 # How fast the bullets are
@export var g = Vector3.DOWN * 5
@onready var bulletAuthority = get_multiplayer_authority()
var velocity = Vector3.ZERO
func _ready():
name = str("bullet ", bulletAuthority, "-0")
func _physics_process(delta):
velocity += g * delta # Bullet gravity
look_at(transform.origin + velocity.normalized(), Vector3.UP)
transform.origin += velocity * delta
if is_multiplayer_authority():
for body in get_overlapping_bodies():
if body.is_in_group("human"):
damage_player()
self.queue_free()
else:
print("Bullet hit something else")
self.queue_free()
await get_tree().create_timer(2).timeout
self.queue_free()
func _on_Shell_body_entered(body):
emit_signal("exploded", transform.origin)
queue_free()
func damage_player():
var damage = RandomNumberGenerator.new().randi_range(7, 16)
Global.playerHealth -= damage
Global.playerHealth

View file

@ -0,0 +1,18 @@
[gd_scene load_steps=4 format=3 uid="uid://cvt3pgmv5o0b3"]
[ext_resource type="Script" path="res://objects/AI-Bullet/Bullet.gd" id="1_sdd7k"]
[ext_resource type="PackedScene" uid="uid://pni78bumc5f5" path="res://objects/Bullet/model/Bullet.dae" id="2_l176h"]
[sub_resource type="BoxShape3D" id="BoxShape3D_jya8v"]
size = Vector3(0.173025, 0.105384, 0.0953652)
[node name="AIBullet" type="Area3D" groups=["bullet"]]
transform = Transform3D(0.979715, 0, 0, 0, 0.979715, 0, 0, 0, 0.979715, 0, 0, 0)
script = ExtResource("1_sdd7k")
[node name="CollisionShape3D" type="CollisionShape3D" parent="." groups=["bullet"]]
transform = Transform3D(0.957696, 0, 0, 0, 1, 0, 0, 0, 1.66763, 2.08165e-12, 0.109855, 2.08165e-12)
shape = SubResource("BoxShape3D_jya8v")
[node name="Bullet" parent="." instance=ExtResource("2_l176h")]
transform = Transform3D(0.05, -6.0734e-17, -2.65477e-24, 0, -2.18557e-09, 0.0499999, -6.0734e-17, -0.05, -2.18557e-09, 2.08165e-12, 0.0990669, 0.0735058)

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,32 @@
[remap]
importer="scene"
importer_version=1
type="PackedScene"
uid="uid://dhbsdt63t5bte"
path="res://.godot/imported/Bullet.dae-abcc0265cc9e8a6d41e90a1aa00ce8eb.scn"
[deps]
source_file="res://objects/AI-Bullet/model/Bullet.dae"
dest_files=["res://.godot/imported/Bullet.dae-abcc0265cc9e8a6d41e90a1aa00ce8eb.scn"]
[params]
nodes/root_type="Node3D"
nodes/root_name="Scene Root"
nodes/apply_root_scale=true
nodes/root_scale=1.0
meshes/ensure_tangents=true
meshes/generate_lods=true
meshes/create_shadow_meshes=true
meshes/light_baking=0
meshes/lightmap_texel_size=0.1
skins/use_named_skins=true
animation/import=true
animation/fps=15
animation/trimming=false
animation/remove_immutable_tracks=true
import_script/path=""
_subresources={}
gltf/embedded_image_handling=1

Binary file not shown.

Binary file not shown.

View file

@ -7,8 +7,6 @@ signal exploded
@onready var bulletAuthority = get_multiplayer_authority()
var velocity = Vector3.ZERO
###### CHEATS
var godmode = 0
func _ready():
name = str("bullet ", bulletAuthority, "-0")
@ -20,7 +18,7 @@ func _physics_process(delta):
if is_multiplayer_authority():
for body in get_overlapping_bodies():
if body.get_path() == Global.selfTeddy: # We need to modify this to make the player not invinsible
if body.get_path() == Global.selfTeddy:
pass
elif body.is_in_group("human"):
var playerShot = body.get_multiplayer_authority()

View file

@ -8,12 +8,13 @@ var health = 100
var bullettimer = 50
var bulletshot = false
var bulletrandom
var dead = false
# Get the gravity from the project settings to be synced with RigidBody nodes.
var gravity = ProjectSettings.get_setting("physics/3d/default_gravity")
var player
@export var Bullet = preload("res://objects/Bullet/Bullet.tscn")
@export var Bullet = preload("res://objects/AI-Bullet/Bullet.tscn")
func _ready():
self.visible = false
@ -31,13 +32,13 @@ func _physics_process(delta):
$CollisionShape3D.disabled = false
if $CollisionShape3D/Neck/Teddy/AnimationPlayer.is_playing() == false and not Global.tutorialComplete:
$CollisionShape3D/Neck/Teddy/AnimationPlayer.play("idle")
if player and Global.playerAlive and Global.tutorialComplete:
if player and Global.playerAlive and Global.tutorialComplete and not dead:
if Global.AIHit == true:
Global.AIHit = false
var damage = RandomNumberGenerator.new().randi_range(7, 16)
health -= damage
if health <= 0:
self.queue_free()
dead_AI()
if $CollisionShape3D/Neck/Teddy/AnimationPlayer.is_playing():
var animation = $CollisionShape3D/Neck/Teddy/AnimationPlayer.get_current_animation()
if animation == "idle":
@ -60,3 +61,14 @@ func _physics_process(delta):
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()
func dead_AI():
health = 100
dead = true
$CollisionShape3D/Neck/Teddy.visible = false
$CollisionShape3D.disabled = true
await get_tree().create_timer(10).timeout
$CollisionShape3D/Neck/Teddy.visible = true
$CollisionShape3D.disabled = false
dead = false