working on rat

This commit is contained in:
derek
2025-05-12 16:43:25 -05:00
parent 4c98bca83b
commit ed3c47e9cf
10 changed files with 119 additions and 92 deletions

View File

@@ -1,34 +1,38 @@
extends Node3D
@export var rat : Resource
@export var spawn_amount = 10 #max amount in level at any given time
@export var spawn_time_max = 5
var rng = RandomNumberGenerator.new()
var spawn_timer
var holes = []
var start_hole_id
var start_hole
var end_hole_id
var end_hole
var hole_length_id
var control_node = self
# Called when the node enters the scene tree for the first time.
func _ready():
holes = get_children()
hole_length_id = holes.size() - 1
func _ready() -> void:
#get holes
for node in self.get_children():
if node is RatHole:
holes.append(node)
print("HOLES : ",holes)
spawn_rat_at_random_hole()
reset_spawn_timer()
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
if spawn_amount > 0:
start_hole_id = rng.randi_range(0,hole_length_id)
start_hole = holes[start_hole_id]
end_hole_id = rng.randi_range(0,hole_length_id)
while start_hole_id == end_hole_id:
end_hole_id = rng.randi_range(0,hole_length_id)
end_hole = holes[end_hole_id]
#spawn rat at first hole and pass position of next hole
start_hole.spawn_rat(end_hole,control_node)
spawn_amount -= 1
func _process(delta: float) -> void:
print("TIME UNTIL NEXT SPAWN : ",spawn_timer)
if spawn_timer > 0:
spawn_timer -= delta
else:
reset_spawn_timer()
spawn_rat_at_random_hole()
func spawn_rat_at_random_hole():
if holes.size() >= 2:
var hole_options = holes.duplicate()
hole_options.shuffle()
var spawn_hole = hole_options.pop_front()
var destination_hole = hole_options.pop_front()
print("SPAWN HOLE : ", spawn_hole)
print("END_HOLE : ",destination_hole)
spawn_hole.spawn_rat(destination_hole)
func reset_spawn_timer():
spawn_timer = randf_range(1,spawn_time_max)

View File

@@ -1,47 +1,27 @@
extends CharacterBody3D
var number_of_drops = 1
const MAX_LV = 20
const MAX_AV = 10
@export var dead_rat : Resource
@export var SPEED = 7
var end_hole
var control_node
var rng = RandomNumberGenerator.new()
@export var SPEED = 5
@export var state_machine : StateMachine
@onready var level_control = get_tree().current_scene
@onready var anim_player = $AnimationPlayer
@onready var nav_agent = $NavigationAgent3D
@onready var ray = $RayCast3D
@onready var ray_2 = $RayCast3D2
@onready var ray_3 = $RayCast3D3
var end_hole
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
const number_of_drops = 1
const MAX_LV = 20
const MAX_AV = 10
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _physics_process(delta):
# Navigation
if end_hole != null: #REMOVE WHEN FIXED LEVEL RELOAD
nav_agent.set_target_position(end_hole.global_transform.origin)
var next_nav_point = nav_agent.get_next_path_position()
velocity = (next_nav_point - global_transform.origin).normalized() * SPEED
look_at(end_hole.global_transform.origin, Vector3.UP)
move_and_slide()
func _process(delta):
move_and_slide()
func breaking(bullet_velocity):
var drops_left = number_of_drops
#pickup drop
while number_of_drops > 0:
while drops_left > 0:
var pickup_spawn = level_control.ITEM_PICKUP.instantiate()
var item_stats = level_control.pickup_spawn(false)
@@ -64,7 +44,7 @@ func breaking(bullet_velocity):
pickup_spawn.linear_velocity += self.global_transform.basis * Vector3(lv_x,lv_y,lv_z)
pickup_spawn.angular_velocity += self.global_transform.basis * Vector3(av_x,av_y,av_z)
get_tree().get_root().add_child(pickup_spawn)
number_of_drops -= 1
drops_left -= 1
#animate dead
var spawn_broken = dead_rat.instantiate()
@@ -80,3 +60,7 @@ func breaking(bullet_velocity):
var pieces = spawn_broken.get_children()
get_tree().get_root().add_child(spawn_broken)
queue_free()
func _on_navigation_agent_3d_velocity_computed(safe_velocity: Vector3) -> void:
state_machine.current_state.velocity_computed(safe_velocity)

View File

@@ -1,26 +1,15 @@
extends Node3D
class_name RatHole
@export var rat : Resource
@onready var ray = $RayCast3D
@onready var spawnpos: Marker3D = $spawnpos
@onready var area_3d = $Area3D
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
pass
func spawn_rat(end_hole,control_node):
func spawn_rat(end_hole):
var spawn_rat = rat.instantiate()
spawn_rat.position = ray.global_position
spawn_rat.transform.basis = ray.global_transform.basis
spawn_rat.look_at_from_position(end_hole.position,Vector3.UP)
spawn_rat.position = spawnpos.global_position
spawn_rat.end_hole = end_hole
get_tree().get_root().add_child(spawn_rat)
get_parent().add_child(spawn_rat)
func _on_area_3d_body_entered(body):
if body.is_in_group("rat"):

12
scripts/rat_walk.gd Normal file
View File

@@ -0,0 +1,12 @@
extends CharacterState
class_name RatWalk
func Update(delta):
get_new_waypoint()
move_to_nav_point(delta)
func get_new_waypoint():
if character.end_hole:
move_target = character.end_hole.global_position
character.nav_agent.set_target_position(move_target)

1
scripts/rat_walk.gd.uid Normal file
View File

@@ -0,0 +1 @@
uid://3bd2b0b8dpmx

View File

@@ -100,9 +100,9 @@ func _ready():
func _process(delta):
line_of_sight.global_position = global_position + Vector3(0,1.5,0)
move_and_slide()
look_at_player()
move_and_slide()
func stun():
change_state_to("stunned")