add sit state and colors to cat
This commit is contained in:
38
core/ai/agents/cat/ai_cat.gd
Normal file
38
core/ai/agents/cat/ai_cat.gd
Normal file
@@ -0,0 +1,38 @@
|
||||
extends AIBase
|
||||
|
||||
class_name AICat
|
||||
|
||||
@export_group("Cat Colors")
|
||||
@export var mesh: MeshInstance3D
|
||||
@export var fur_colors: Array[Color] = []
|
||||
@export var eye_colors: Array[Color] = []
|
||||
|
||||
@export var fur_material_index: int = 0
|
||||
@export var eye_material_index: int = 1
|
||||
|
||||
func _ready() -> void:
|
||||
super._ready()
|
||||
_apply_random_color()
|
||||
|
||||
func _apply_random_color() -> void:
|
||||
if fur_colors.is_empty() or eye_colors.is_empty():
|
||||
return
|
||||
|
||||
if not mesh or not mesh.mesh:
|
||||
return
|
||||
|
||||
var max_index = min(fur_colors.size(), eye_colors.size())
|
||||
var random_idx = randi() % max_index
|
||||
|
||||
_override_material_color(mesh, fur_material_index, fur_colors[random_idx])
|
||||
_override_material_color(mesh, eye_material_index, eye_colors[random_idx])
|
||||
|
||||
func _override_material_color(mesh_node: MeshInstance3D, surface_idx: int, color: Color) -> void:
|
||||
if surface_idx < 0 or surface_idx >= mesh_node.mesh.get_surface_count():
|
||||
return
|
||||
|
||||
var mat = mesh_node.mesh.surface_get_material(surface_idx)
|
||||
if mat and mat is StandardMaterial3D:
|
||||
var new_mat = mat.duplicate() as StandardMaterial3D
|
||||
new_mat.albedo_color = color
|
||||
mesh_node.set_surface_override_material(surface_idx, new_mat)
|
||||
Reference in New Issue
Block a user