Compare commits

...

2 Commits

4 changed files with 45 additions and 10 deletions

View File

@ -2,12 +2,20 @@ extends Node3D
@onready var animation_state: AnimationNodeStateMachinePlayback = $AnimationTree.get("parameters/playback") @onready var animation_state: AnimationNodeStateMachinePlayback = $AnimationTree.get("parameters/playback")
@export var colors: Array[Color] @export var colors: Array[Color]
@onready var color_idx: int = randi()
var mat: Material
func _ready(): func _ready():
var color = colors[randi() % colors.size()] mat = $Armature/Skeleton3D/Slime.get_active_material(3).duplicate()
var mat = $Armature/Skeleton3D/Slime.get_active_material(3).duplicate()
$Armature/Skeleton3D/Slime.set_surface_override_material(3, mat) $Armature/Skeleton3D/Slime.set_surface_override_material(3, mat)
$Armature/Skeleton3D/Slime.get_active_material(3).albedo_color = color var color = colors[randi() % colors.size()]
mat.albedo_color = color
func change_color(idx: int):
color_idx = idx % colors.size()
var color = colors[color_idx]
get_tree().create_tween().tween_property(mat, "albedo_color", color, .3)
func walk(): func walk():
animation_state.travel("Walk") animation_state.travel("Walk")

View File

@ -1,2 +1,24 @@
extends SharedSlime extends SharedSlime
class_name Villager class_name Villager
var color_changes = true
func get_color_idx() -> int:
return $slime.color_idx
func _on_area_3d_body_entered(body):
if "color_changes" not in body:
return
var other = body.get_color_idx()
var mine = get_color_idx()
print(other, mine)
if other == mine:
return
var delta = abs(other - mine)
if delta % 2 == 0:
if mine < other:
$slime.change_color(other)
elif mine > other:
$slime.change_color(other)

View File

@ -33,7 +33,7 @@ script = ExtResource("3_a68da")
[node name="Area3D" type="Area3D" parent="Holster"] [node name="Area3D" type="Area3D" parent="Holster"]
[node name="CollisionShape3D" type="CollisionShape3D" parent="Holster/Area3D"] [node name="CollisionShape3D" type="CollisionShape3D" parent="Holster/Area3D"]
transform = Transform3D(0.1, 0, 0, 0, 0.1, 0, 0, 0, 0.1, 0, 0.0469455, 0) transform = Transform3D(0.1, 0, 0, 0, 0.1, 0, 0, 0, 0.1, 0, 0, 0)
shape = SubResource("SphereShape3D_6l1w6") shape = SubResource("SphereShape3D_6l1w6")
[connection signal="anim_check_grab" from="grape_man" to="." method="_on_grape_man_anim_check_grab"] [connection signal="anim_check_grab" from="grape_man" to="." method="_on_grape_man_anim_check_grab"]

View File

@ -1,12 +1,17 @@
[gd_scene load_steps=3 format=3 uid="uid://c4s6y758n77lw"] [gd_scene load_steps=4 format=3 uid="uid://c4s6y758n77lw"]
[ext_resource type="PackedScene" uid="uid://dmtmign72vtlm" path="res://slime_shared.tscn" id="1_qm1jp"] [ext_resource type="PackedScene" uid="uid://dmtmign72vtlm" path="res://slime_shared.tscn" id="1_qm1jp"]
[ext_resource type="Script" path="res://Villager.gd" id="2_uf6mh"] [ext_resource type="Script" path="res://Villager.gd" id="2_uf6mh"]
[sub_resource type="SphereShape3D" id="SphereShape3D_0wi6w"]
radius = 0.1
[node name="villager" instance=ExtResource("1_qm1jp")] [node name="villager" instance=ExtResource("1_qm1jp")]
script = ExtResource("2_uf6mh") script = ExtResource("2_uf6mh")
walk_chance = 0.1
spin_chance = 0.2 [node name="Area3D" type="Area3D" parent="." index="2"]
walk_speed = 0.5
dir_correction_rate = 0.95 [node name="CollisionShape3D" type="CollisionShape3D" parent="Area3D" index="0"]
dir_accuracy = 0.00174533 shape = SubResource("SphereShape3D_0wi6w")
[connection signal="body_entered" from="Area3D" to="." method="_on_area_3d_body_entered"]