This commit is contained in:
ncusimano 2023-08-19 23:07:52 -06:00
parent d67300d8b8
commit 4f2ba4f642
13 changed files with 271 additions and 42 deletions

View File

@ -4,7 +4,7 @@
[ext_resource type="PackedScene" uid="uid://b35w4hlh4n1jt" path="res://Level/World/world_environment.tscn" id="2_lerrn"] [ext_resource type="PackedScene" uid="uid://b35w4hlh4n1jt" path="res://Level/World/world_environment.tscn" id="2_lerrn"]
[ext_resource type="PackedScene" uid="uid://d3ccrfjpg4hbv" path="res://Models/palm_curved.tscn" id="3_bth2b"] [ext_resource type="PackedScene" uid="uid://d3ccrfjpg4hbv" path="res://Models/palm_curved.tscn" id="3_bth2b"]
[ext_resource type="PackedScene" uid="uid://c1n2lfcn4rkx7" path="res://Models/palm_default.tscn" id="4_2cnue"] [ext_resource type="PackedScene" uid="uid://c1n2lfcn4rkx7" path="res://Models/palm_default.tscn" id="4_2cnue"]
[ext_resource type="PackedScene" uid="uid://ctbyl0qbks4k6" path="res://Models/ocean.tscn" id="4_dey2i"] [ext_resource type="PackedScene" path="res://Models/ocean.tscn" id="4_dey2i"]
[ext_resource type="PackedScene" uid="uid://difi2tur2j4dg" path="res://Models/island.tscn" id="4_lq6cy"] [ext_resource type="PackedScene" uid="uid://difi2tur2j4dg" path="res://Models/island.tscn" id="4_lq6cy"]
[ext_resource type="PackedScene" uid="uid://hg1yr5rnxd47" path="res://Models/palm_young.tscn" id="5_prlw2"] [ext_resource type="PackedScene" uid="uid://hg1yr5rnxd47" path="res://Models/palm_young.tscn" id="5_prlw2"]
[ext_resource type="PackedScene" uid="uid://ce7jbp7f55cro" path="res://Models/buildings/building_1.tscn" id="8_6qbns"] [ext_resource type="PackedScene" uid="uid://ce7jbp7f55cro" path="res://Models/buildings/building_1.tscn" id="8_6qbns"]

View File

@ -7,6 +7,7 @@
[ext_resource type="AudioStream" uid="uid://b80t5xqckjoqk" path="res://Sounds/heartychuckle.ogg" id="5_b32re"] [ext_resource type="AudioStream" uid="uid://b80t5xqckjoqk" path="res://Sounds/heartychuckle.ogg" id="5_b32re"]
[sub_resource type="AnimationNodeAdd2" id="AnimationNodeAdd2_a0vxm"] [sub_resource type="AnimationNodeAdd2" id="AnimationNodeAdd2_a0vxm"]
filter_enabled = true
filters = ["rig/Skeleton3D:forearm.L", "rig/Skeleton3D:forearm.R", "rig/Skeleton3D:head", "rig/Skeleton3D:upper_arm.L", "rig/Skeleton3D:upper_arm.R"] filters = ["rig/Skeleton3D:forearm.L", "rig/Skeleton3D:forearm.R", "rig/Skeleton3D:head", "rig/Skeleton3D:upper_arm.L", "rig/Skeleton3D:upper_arm.R"]
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_s8uqe"] [sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_s8uqe"]
@ -16,7 +17,7 @@ animation = &"UpperBodyIdle"
animation = &"Idle" animation = &"Idle"
[sub_resource type="AnimationNodeBlendTree" id="AnimationNodeBlendTree_ojr1k"] [sub_resource type="AnimationNodeBlendTree" id="AnimationNodeBlendTree_ojr1k"]
graph_offset = Vector2(-74, 44) graph_offset = Vector2(-312, -69)
nodes/Add2/node = SubResource("AnimationNodeAdd2_a0vxm") nodes/Add2/node = SubResource("AnimationNodeAdd2_a0vxm")
nodes/Add2/position = Vector2(160, 80) nodes/Add2/position = Vector2(160, 80)
nodes/Animation/node = SubResource("AnimationNodeAnimation_4ft7i") nodes/Animation/node = SubResource("AnimationNodeAnimation_4ft7i")
@ -26,6 +27,7 @@ nodes/Animation/position = Vector2(0, 80)
node_connections = [&"output", 0, &"Add2", &"Add2", 0, &"Animation", &"Add2", 1, &"Animation 2"] node_connections = [&"output", 0, &"Add2", &"Add2", 0, &"Animation", &"Add2", 1, &"Animation 2"]
[sub_resource type="AnimationNodeAdd2" id="AnimationNodeAdd2_4gk6k"] [sub_resource type="AnimationNodeAdd2" id="AnimationNodeAdd2_4gk6k"]
filter_enabled = true
filters = ["rig/Skeleton3D:forearm.L", "rig/Skeleton3D:forearm.R", "rig/Skeleton3D:head", "rig/Skeleton3D:upper_arm.L", "rig/Skeleton3D:upper_arm.R"] filters = ["rig/Skeleton3D:forearm.L", "rig/Skeleton3D:forearm.R", "rig/Skeleton3D:head", "rig/Skeleton3D:upper_arm.L", "rig/Skeleton3D:upper_arm.R"]
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_alnh1"] [sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_alnh1"]
@ -49,6 +51,7 @@ node_connections = [&"output", 0, &"Add2", &"Add2", 0, &"Animation", &"Add2", 1,
animation = &"Pickup" animation = &"Pickup"
[sub_resource type="AnimationNodeAdd2" id="AnimationNodeAdd2_rd6bn"] [sub_resource type="AnimationNodeAdd2" id="AnimationNodeAdd2_rd6bn"]
filter_enabled = true
filters = ["rig/Skeleton3D:forearm.L", "rig/Skeleton3D:forearm.R", "rig/Skeleton3D:head", "rig/Skeleton3D:upper_arm.L", "rig/Skeleton3D:upper_arm.R"] filters = ["rig/Skeleton3D:forearm.L", "rig/Skeleton3D:forearm.R", "rig/Skeleton3D:head", "rig/Skeleton3D:upper_arm.L", "rig/Skeleton3D:upper_arm.R"]
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_7s7tg"] [sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_7s7tg"]
@ -58,7 +61,7 @@ animation = &"UpperBodyIdle"
animation = &"Walk" animation = &"Walk"
[sub_resource type="AnimationNodeBlendTree" id="AnimationNodeBlendTree_6rmmo"] [sub_resource type="AnimationNodeBlendTree" id="AnimationNodeBlendTree_6rmmo"]
graph_offset = Vector2(-384.186, 6.2577) graph_offset = Vector2(-358.186, -79.7423)
nodes/Add2/node = SubResource("AnimationNodeAdd2_rd6bn") nodes/Add2/node = SubResource("AnimationNodeAdd2_rd6bn")
nodes/Add2/position = Vector2(140, 80) nodes/Add2/position = Vector2(140, 80)
nodes/Animation/node = SubResource("AnimationNodeAnimation_ir63n") nodes/Animation/node = SubResource("AnimationNodeAnimation_ir63n")
@ -68,6 +71,7 @@ nodes/Animation/position = Vector2(-40, 60)
node_connections = [&"output", 0, &"Add2", &"Add2", 0, &"Animation", &"Add2", 1, &"Animation 2"] node_connections = [&"output", 0, &"Add2", &"Add2", 0, &"Animation", &"Add2", 1, &"Animation 2"]
[sub_resource type="AnimationNodeAdd2" id="AnimationNodeAdd2_sv87c"] [sub_resource type="AnimationNodeAdd2" id="AnimationNodeAdd2_sv87c"]
filter_enabled = true
filters = ["rig/Skeleton3D:forearm.L", "rig/Skeleton3D:forearm.R", "rig/Skeleton3D:head", "rig/Skeleton3D:upper_arm.L", "rig/Skeleton3D:upper_arm.R"] filters = ["rig/Skeleton3D:forearm.L", "rig/Skeleton3D:forearm.R", "rig/Skeleton3D:head", "rig/Skeleton3D:upper_arm.L", "rig/Skeleton3D:upper_arm.R"]
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_y7bu0"] [sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_y7bu0"]
@ -146,14 +150,14 @@ states/WalkEmpty/position = Vector2(548, 208)
states/WalkHold/node = SubResource("AnimationNodeBlendTree_kalnq") states/WalkHold/node = SubResource("AnimationNodeBlendTree_kalnq")
states/WalkHold/position = Vector2(351, 323) states/WalkHold/position = Vector2(351, 323)
transitions = ["Start", "IdleEmpty", SubResource("AnimationNodeStateMachineTransition_8sw6d"), "IdleEmpty", "WalkHold", SubResource("AnimationNodeStateMachineTransition_71rn8"), "WalkHold", "IdleEmpty", SubResource("AnimationNodeStateMachineTransition_cp7lp"), "WalkEmpty", "IdleEmpty", SubResource("AnimationNodeStateMachineTransition_27n2r"), "IdleEmpty", "WalkEmpty", SubResource("AnimationNodeStateMachineTransition_v26jl"), "IdleHold", "WalkHold", SubResource("AnimationNodeStateMachineTransition_u0rau"), "IdleHold", "WalkEmpty", SubResource("AnimationNodeStateMachineTransition_1hqga"), "WalkEmpty", "IdleHold", SubResource("AnimationNodeStateMachineTransition_uekhs"), "WalkHold", "IdleHold", SubResource("AnimationNodeStateMachineTransition_652wi"), "IdleEmpty", "Pickup", SubResource("AnimationNodeStateMachineTransition_sdgve"), "Pickup", "IdleEmpty", SubResource("AnimationNodeStateMachineTransition_otprv"), "IdleEmpty", "IdleHold", SubResource("AnimationNodeStateMachineTransition_fbwhh"), "IdleHold", "IdleEmpty", SubResource("AnimationNodeStateMachineTransition_4rq7a"), "WalkHold", "WalkEmpty", SubResource("AnimationNodeStateMachineTransition_oange"), "WalkEmpty", "WalkHold", SubResource("AnimationNodeStateMachineTransition_et4tx"), "Pickup", "IdleHold", SubResource("AnimationNodeStateMachineTransition_y2dr5")] transitions = ["Start", "IdleEmpty", SubResource("AnimationNodeStateMachineTransition_8sw6d"), "IdleEmpty", "WalkHold", SubResource("AnimationNodeStateMachineTransition_71rn8"), "WalkHold", "IdleEmpty", SubResource("AnimationNodeStateMachineTransition_cp7lp"), "WalkEmpty", "IdleEmpty", SubResource("AnimationNodeStateMachineTransition_27n2r"), "IdleEmpty", "WalkEmpty", SubResource("AnimationNodeStateMachineTransition_v26jl"), "IdleHold", "WalkHold", SubResource("AnimationNodeStateMachineTransition_u0rau"), "IdleHold", "WalkEmpty", SubResource("AnimationNodeStateMachineTransition_1hqga"), "WalkEmpty", "IdleHold", SubResource("AnimationNodeStateMachineTransition_uekhs"), "WalkHold", "IdleHold", SubResource("AnimationNodeStateMachineTransition_652wi"), "IdleEmpty", "Pickup", SubResource("AnimationNodeStateMachineTransition_sdgve"), "Pickup", "IdleEmpty", SubResource("AnimationNodeStateMachineTransition_otprv"), "IdleEmpty", "IdleHold", SubResource("AnimationNodeStateMachineTransition_fbwhh"), "IdleHold", "IdleEmpty", SubResource("AnimationNodeStateMachineTransition_4rq7a"), "WalkHold", "WalkEmpty", SubResource("AnimationNodeStateMachineTransition_oange"), "WalkEmpty", "WalkHold", SubResource("AnimationNodeStateMachineTransition_et4tx"), "Pickup", "IdleHold", SubResource("AnimationNodeStateMachineTransition_y2dr5")]
graph_offset = Vector2(3, 172) graph_offset = Vector2(26, 89)
[node name="grape_man" instance=ExtResource("1_fh5yr")] [node name="grape_man" instance=ExtResource("1_fh5yr")]
transform = Transform3D(0.065, 0, 0, 0, 0.065, 0, 0, 0, 0.065, 0, 0, 0) transform = Transform3D(0.065, 0, 0, 0, 0.065, 0, 0, 0, 0.065, 0, 0, 0)
script = ExtResource("2_ksje8") script = ExtResource("2_ksje8")
[node name="Skeleton3D" parent="rig" index="0"] [node name="Skeleton3D" parent="rig" index="0"]
bones/0/rotation = Quaternion(0.0962932, 0, 0, 0.995353) bones/0/rotation = Quaternion(0.0890031, 0, 0, 0.996031)
bones/1/rotation = Quaternion(-0.0891896, 1.18734e-07, -1.06322e-08, 0.996015) bones/1/rotation = Quaternion(-0.0891896, 1.18734e-07, -1.06322e-08, 0.996015)
bones/2/rotation = Quaternion(0.0133933, -1.19199e-07, 1.5966e-09, 0.99991) bones/2/rotation = Quaternion(0.0133933, -1.19199e-07, 1.5966e-09, 0.99991)
bones/3/rotation = Quaternion(-0.00997737, 0.100365, -0.694951, 0.711948) bones/3/rotation = Quaternion(-0.00997737, 0.100365, -0.694951, 0.711948)

View File

@ -1,26 +1,5 @@
extends SharedSlime extends SharedSlime
class_name Villager
var rng = RandomNumberGenerator.new()
@onready var target_location_xz = transform.origin * Vector3(1, 0, 1)
@onready var location_xz = transform.origin * Vector3(1, 0, 1)
@onready var target_direction_xz = (transform.basis * Vector3(1, 0, 1)).normalized()
@onready var direction_xz = (transform.basis * Vector3(1, 0, 1)).normalized()
var task = "idle"
# Percentage chances of the character performing certain actions while idle.
@export var walk_chance = 0.1
@export var spin_chance = 0.2
@export var walk_speed = 0.5
# Rate at which character corrects their direction after going off course (percentage).
@export var dir_correction_rate = 0.95
# Margin of accuracy to which the character will correct their direction when off course (radians).
@export var dir_accuracy = deg_to_rad(0.1)
# Get the gravity from the project settings to be synced with RigidBody nodes.
var gravity = ProjectSettings.get_setting("physics/3d/default_gravity")
# Called when the node enters the scene tree for the first time. # Called when the node enters the scene tree for the first time.
func _ready(): func _ready():

52
godot/cul5E74.tmp Normal file
View File

@ -0,0 +1,52 @@
[gd_scene load_steps=7 format=3 uid="uid://e0s4phx2jiit"]
[ext_resource type="Texture2D" uid="uid://df0xror4t3gbc" path="res://Default Purple.png" id="1_x8j7f"]
[sub_resource type="GDScript" id="GDScript_bumf5"]
script/source = "extends SharedSlime
class_name Cultist
const SPEED = 5.0
const JUMP_VELOCITY = 4.
func _on_area_3d_body_entered(body):
var items_in_range = $Area3D.get_overlapping_bodies()
var villagers = []
for item in items_in_range:
if is_class(\"Villager\"):
villagers.append(item)
var rng = RandomNumberGenerator.new()
var victim_num = rng.randi_range(0, count(villagers))
"
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_y0hcm"]
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_vxnad"]
albedo_texture = ExtResource("1_x8j7f")
[sub_resource type="CapsuleMesh" id="CapsuleMesh_17ljq"]
material = SubResource("StandardMaterial3D_vxnad")
[sub_resource type="SphereShape3D" id="SphereShape3D_sleix"]
radius = 20.0
[node name="Cultist" type="CharacterBody3D"]
script = SubResource("GDScript_bumf5")
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
shape = SubResource("CapsuleShape3D_y0hcm")
[node name="MeshInstance3D" type="MeshInstance3D" parent="CollisionShape3D"]
mesh = SubResource("CapsuleMesh_17ljq")
[node name="Area3D" type="Area3D" parent="."]
[node name="CollisionShape3D" type="CollisionShape3D" parent="Area3D"]
shape = SubResource("SphereShape3D_sleix")
[connection signal="body_entered" from="Area3D" to="." method="_on_area_3d_body_entered"]

78
godot/cul99AE.tmp Normal file
View File

@ -0,0 +1,78 @@
[gd_scene load_steps=7 format=3 uid="uid://e0s4phx2jiit"]
[ext_resource type="Texture2D" uid="uid://df0xror4t3gbc" path="res://Default Purple.png" id="1_x8j7f"]
[sub_resource type="GDScript" id="GDScript_bumf5"]
script/source = "extends SharedSlime
class_name Cultist
const SPEED = 5.0
const JUMP_VELOCITY = 4.
func _process(delta):
pass
func _physics_process(delta):
# Add the gravity.
if not is_on_floor():
velocity.y -= gravity * delta
# Handle Jump.
if Input.is_action_just_pressed(\"ui_accept\") and is_on_floor():
velocity.y = JUMP_VELOCITY
# Get the input direction and handle the movement/deceleration.
# As good practice, you should replace UI actions with custom gameplay actions.
var input_dir = Input.get_vector(\"ui_left\", \"ui_right\", \"ui_up\", \"ui_down\")
var direction = (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
if direction:
velocity.x = direction.x * SPEED
velocity.z = direction.z * SPEED
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
velocity.z = move_toward(velocity.z, 0, SPEED)
move_and_slide()
func _on_area_3d_body_entered(body):
var items_in_range = $Area3D.get_overlapping_bodies()
var villagers = []
for item in items_in_range:
if is_class(\"Villager\"):
villagers.append(item)
var rng = RandomNumberGenerator.new()
var victim_num = rng.randi_range(0, villagers.count())
"
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_y0hcm"]
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_vxnad"]
albedo_texture = ExtResource("1_x8j7f")
[sub_resource type="CapsuleMesh" id="CapsuleMesh_17ljq"]
material = SubResource("StandardMaterial3D_vxnad")
[sub_resource type="SphereShape3D" id="SphereShape3D_sleix"]
radius = 20.0
[node name="Cultist" type="CharacterBody3D"]
script = SubResource("GDScript_bumf5")
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
shape = SubResource("CapsuleShape3D_y0hcm")
[node name="MeshInstance3D" type="MeshInstance3D" parent="CollisionShape3D"]
mesh = SubResource("CapsuleMesh_17ljq")
[node name="Area3D" type="Area3D" parent="."]
[node name="CollisionShape3D" type="CollisionShape3D" parent="Area3D"]
shape = SubResource("SphereShape3D_sleix")
[connection signal="body_entered" from="Area3D" to="." method="_on_area_3d_body_entered"]

View File

@ -1,7 +1,29 @@
[gd_scene load_steps=5 format=3 uid="uid://e0s4phx2jiit"] [gd_scene load_steps=7 format=3 uid="uid://e0s4phx2jiit"]
[ext_resource type="Texture2D" uid="uid://df0xror4t3gbc" path="res://Default Purple.png" id="1_x8j7f"] [ext_resource type="Texture2D" uid="uid://df0xror4t3gbc" path="res://Default Purple.png" id="1_x8j7f"]
[sub_resource type="GDScript" id="GDScript_bumf5"]
script/source = "extends SharedSlime
class_name Cultist
const SPEED = 5.0
const JUMP_VELOCITY = 4.
func _on_area_3d_body_entered(body):
var items_in_range = $Area3D.get_overlapping_bodies()
var villagers = []
for item in items_in_range:
if is_class(\"Villager\"):
villagers.append(item)
var rng = RandomNumberGenerator.new()
var victim_num = rng.randi_range(0, villagers.size())
"
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_y0hcm"] [sub_resource type="CapsuleShape3D" id="CapsuleShape3D_y0hcm"]
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_vxnad"] [sub_resource type="StandardMaterial3D" id="StandardMaterial3D_vxnad"]
@ -10,12 +32,21 @@ albedo_texture = ExtResource("1_x8j7f")
[sub_resource type="CapsuleMesh" id="CapsuleMesh_17ljq"] [sub_resource type="CapsuleMesh" id="CapsuleMesh_17ljq"]
material = SubResource("StandardMaterial3D_vxnad") material = SubResource("StandardMaterial3D_vxnad")
[node name="Node3D" type="Node3D"] [sub_resource type="SphereShape3D" id="SphereShape3D_sleix"]
radius = 20.0
[node name="RigidBody3D" type="RigidBody3D" parent="."] [node name="Cultist" type="CharacterBody3D"]
script = SubResource("GDScript_bumf5")
[node name="CollisionShape3D" type="CollisionShape3D" parent="RigidBody3D"] [node name="CollisionShape3D" type="CollisionShape3D" parent="."]
shape = SubResource("CapsuleShape3D_y0hcm") shape = SubResource("CapsuleShape3D_y0hcm")
[node name="MeshInstance3D" type="MeshInstance3D" parent="RigidBody3D/CollisionShape3D"] [node name="MeshInstance3D" type="MeshInstance3D" parent="CollisionShape3D"]
mesh = SubResource("CapsuleMesh_17ljq") mesh = SubResource("CapsuleMesh_17ljq")
[node name="Area3D" type="Area3D" parent="."]
[node name="CollisionShape3D" type="CollisionShape3D" parent="Area3D"]
shape = SubResource("SphereShape3D_sleix")
[connection signal="body_entered" from="Area3D" to="." method="_on_area_3d_body_entered"]

View File

@ -1,7 +1,7 @@
[gd_scene load_steps=6 format=3 uid="uid://7utef1nnena8"] [gd_scene load_steps=6 format=3 uid="uid://7utef1nnena8"]
[ext_resource type="Script" path="res://Player.gd" id="1_7gpdp"] [ext_resource type="Script" path="res://Player.gd" id="1_7gpdp"]
[ext_resource type="PackedScene" uid="uid://bgoo1lbt28na" path="res://Models/grape_man.tscn" id="2_ctyy5"] [ext_resource type="Script" path="res://Models/grape_man.gd" id="2_u6jps"]
[ext_resource type="Script" path="res://Holster.gd" id="3_a68da"] [ext_resource type="Script" path="res://Holster.gd" id="3_a68da"]
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_kb4ms"] [sub_resource type="CapsuleShape3D" id="CapsuleShape3D_kb4ms"]
@ -17,7 +17,9 @@ script = ExtResource("1_7gpdp")
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.21, 0) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.21, 0)
shape = SubResource("CapsuleShape3D_kb4ms") shape = SubResource("CapsuleShape3D_kb4ms")
[node name="grape_man" parent="." instance=ExtResource("2_ctyy5")] [node name="grape_man" type="Node3D" parent="."]
transform = Transform3D(0.065, 0, 0, 0, 0.065, 0, 0, 0, 0.065, 0, 0, 0)
script = ExtResource("2_u6jps")
[node name="CameraMount" type="Node3D" parent="."] [node name="CameraMount" type="Node3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.3, 0) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.3, 0)
@ -35,7 +37,3 @@ script = ExtResource("3_a68da")
[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, 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="body_entered" from="Holster/Area3D" to="." method="_on_holster_enter"]
[connection signal="body_exited" from="Holster/Area3D" to="." method="_on_holster_exit"]

View File

@ -3,12 +3,98 @@ class_name SharedSlime
var is_holdable: bool = true var is_holdable: bool = true
var rng = RandomNumberGenerator.new()
@onready var target_location_xz = transform.origin * Vector3(1, 0, 1)
@onready var location_xz = transform.origin * Vector3(1, 0, 1)
@onready var target_direction_xz = (transform.basis * Vector3(1, 0, 1)).normalized()
@onready var direction_xz = (transform.basis * Vector3(1, 0, 1)).normalized()
var task = "idle"
# Percentage chances of the character performing certain actions while idle.
@export var walk_chance = 0.1
@export var spin_chance = 0.2
@export var walk_speed = 0.5
# Rate at which character corrects their direction after going off course (percentage).
@export var dir_correction_rate = 0.95
# Margin of accuracy to which the character will correct their direction when off course (radians).
@export var dir_accuracy = deg_to_rad(0.1)
# Get the gravity from the project settings to be synced with RigidBody nodes.
var gravity = ProjectSettings.get_setting("physics/3d/default_gravity")
func _ready(): func _ready():
$slime.foo() $slime.foo()
$slime.idle() $slime.idle()
func walk(): func walk():
$slime.walk() $slime.walk()
# Get the direction to the target in z-x plane.
target_direction_xz = (location_xz.direction_to(target_location_xz) * Vector3(1, 0, 1)).normalized()
# Continue to correct direction to within a margin of dir_accuracy degrees.
if direction_xz.angle_to(target_direction_xz) >= dir_accuracy:
# Rotate towards destination at specified percentage rate.
rotate_y(direction_xz.angle_to(target_direction_xz) * dir_correction_rate)
if location_xz.distance_to(target_location_xz) <= (Vector2(direction_xz.x, direction_xz.z) * walk_speed).length():
target_direction_xz = direction_xz
target_location_xz = location_xz
task = "idle"
func spin():
# Continue to correct direction to within a margin of dir_accuracy degrees.
if direction_xz.angle_to(target_direction_xz) >= dir_accuracy:
# Rotate towards destination at specified percentage rate.
rotate_y(direction_xz.angle_to(target_direction_xz) * dir_correction_rate)
else:
task = "idle"
func idle(): func idle():
$slime.idle() $slime.idle()
task = rng.randf_range(0, 100)
# 3% chance to walk somewhere.
if task <= walk_chance:
task = "walk"
target_location_xz = transform.origin * Vector3(1, 0, 1) + (direction_xz * 4)
# 6% chance to rotate.
elif task > walk_chance and task <= (walk_chance + spin_chance):
task = "spin"
var rotation_angle = rng.randf_range(-2*PI, 2*PI)
var rotation_vector = Vector3(cos(rotation_angle), 0, sin(rotation_angle))
target_direction_xz = direction_xz + rotation_vector
# 90% chance to idle.
elif task > (spin_chance + walk_chance):
task = "idle"
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(_delta):
location_xz = transform.origin * Vector3(1, 0, 1)
direction_xz = (transform.basis * Vector3(1, 0, 1)).normalized()
match task:
"idle":
idle()
"walk":
walk()
"spin":
spin()
func _physics_process(delta):
# Add the gravity.
if not is_on_floor():
velocity.y -= gravity * delta
# Walk to target location.
if (location_xz.distance_to(target_location_xz) > walk_speed) and task == "walk":
velocity.x = direction_xz.x * walk_speed
velocity.z = direction_xz.z * walk_speed
else:
velocity.x = 0
velocity.z = 0
move_and_slide()

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=4 format=3 uid="uid://dmtmign72vtlm"] [gd_scene load_steps=4 format=3 uid="uid://b24gutwqacwyr"]
[ext_resource type="Script" path="res://slime_shared.gd" id="1_gmj2r"] [ext_resource type="Script" path="res://slime_shared.gd" id="1_gmj2r"]
[ext_resource type="PackedScene" uid="uid://c3q6fva1c1baa" path="res://Models/slime.tscn" id="2_6u4ex"] [ext_resource type="PackedScene" uid="uid://c3q6fva1c1baa" path="res://Models/slime.tscn" id="2_6u4ex"]
@ -10,6 +10,7 @@ radius = 0.05
script = ExtResource("1_gmj2r") script = ExtResource("1_gmj2r")
[node name="slime" parent="." instance=ExtResource("2_6u4ex")] [node name="slime" parent="." instance=ExtResource("2_6u4ex")]
colors = Array[Color]([])
[node name="slime_collision" type="CollisionShape3D" parent="."] [node name="slime_collision" type="CollisionShape3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.0408143, 0) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.0408143, 0)

View File

@ -1,7 +1,7 @@
[gd_scene load_steps=5 format=3 uid="uid://bax01mdng0pbb"] [gd_scene load_steps=5 format=3 uid="uid://cl42bns6d4401"]
[ext_resource type="PackedScene" uid="uid://7utef1nnena8" path="res://player.tscn" id="2_fy870"] [ext_resource type="PackedScene" uid="uid://7utef1nnena8" path="res://player.tscn" id="2_fy870"]
[ext_resource type="PackedScene" uid="uid://c4s6y758n77lw" path="res://villager_shared.tscn" id="2_oxniy"] [ext_resource type="PackedScene" path="res://villager_shared.tscn" id="2_oxniy"]
[sub_resource type="QuadMesh" id="QuadMesh_lasv3"] [sub_resource type="QuadMesh" id="QuadMesh_lasv3"]

View File

@ -6,7 +6,7 @@
[sub_resource type="CapsuleMesh" id="CapsuleMesh_b3srs"] [sub_resource type="CapsuleMesh" id="CapsuleMesh_b3srs"]
[node name="CharacterBody3D" type="CharacterBody3D"] [node name="Villager" type="CharacterBody3D"]
script = ExtResource("1_ardgw") script = ExtResource("1_ardgw")
[node name="CollisionShape3D" type="CollisionShape3D" parent="."] [node name="CollisionShape3D" type="CollisionShape3D" parent="."]