50 lines
1.3 KiB
GDScript
50 lines
1.3 KiB
GDScript
extends CharacterBody3D
|
|
|
|
|
|
@export var dead_rat : Resource
|
|
@export var SPEED = 7
|
|
var end_hole
|
|
var control_node
|
|
var rng = RandomNumberGenerator.new()
|
|
|
|
@onready var anim_player = $AnimationPlayer
|
|
@onready var nav_agent = $NavigationAgent3D
|
|
@onready var ray = $RayCast3D
|
|
@onready var ray_2 = $RayCast3D2
|
|
@onready var ray_3 = $RayCast3D3
|
|
|
|
|
|
# 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 _physics_process(delta):
|
|
|
|
|
|
# Navigation
|
|
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 breaking(bullet_velocity):
|
|
var spawn_broken = dead_rat.instantiate()
|
|
spawn_broken.position = global_position
|
|
spawn_broken.transform.basis = global_transform.basis
|
|
spawn_broken.rotation = rotation
|
|
var bits = spawn_broken.get_children()
|
|
for bit in bits:
|
|
if bit is RigidBody3D:
|
|
bit.linear_velocity += bullet_velocity
|
|
if bit is GPUParticles3D:
|
|
bit.emitting = true
|
|
var pieces = spawn_broken.get_children()
|
|
get_tree().get_root().add_child(spawn_broken)
|
|
queue_free()
|