This commit is contained in:
Spencer Killen 2023-08-20 00:08:32 -06:00
commit ea195e54cc
Signed by: sjkillen
GPG Key ID: F307025B65C860BA
9 changed files with 161 additions and 101 deletions

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=4 format=3 uid="uid://ce7jbp7f55cro"] [gd_scene load_steps=5 format=3 uid="uid://ce7jbp7f55cro"]
[ext_resource type="PackedScene" uid="uid://cchgdggcbyk6f" path="res://Models/buildings/building_01.1.glb" id="1_8lstr"] [ext_resource type="PackedScene" uid="uid://cchgdggcbyk6f" path="res://Models/buildings/building_01.1.glb" id="1_8lstr"]
[ext_resource type="Texture2D" uid="uid://b4qbyum6h2mhf" path="res://Textures/building_01.png" id="2_w406q"] [ext_resource type="Texture2D" uid="uid://b4qbyum6h2mhf" path="res://Textures/building_01.png" id="2_w406q"]
@ -6,7 +6,16 @@
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_i2ykn"] [sub_resource type="StandardMaterial3D" id="StandardMaterial3D_i2ykn"]
albedo_texture = ExtResource("2_w406q") albedo_texture = ExtResource("2_w406q")
[sub_resource type="BoxShape3D" id="BoxShape3D_hr7fu"]
size = Vector3(0.183504, 0.527655, 0.184908)
[node name="building_01_1" instance=ExtResource("1_8lstr")] [node name="building_01_1" instance=ExtResource("1_8lstr")]
[node name="node_id4" parent="root" index="0"] [node name="node_id4" parent="root" index="0"]
surface_material_override/0 = SubResource("StandardMaterial3D_i2ykn") surface_material_override/0 = SubResource("StandardMaterial3D_i2ykn")
[node name="StaticBody3D" type="StaticBody3D" parent="root" index="1"]
[node name="CollisionShape3D" type="CollisionShape3D" parent="root/StaticBody3D" index="0"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0.251368)
shape = SubResource("BoxShape3D_hr7fu")

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=4 format=3 uid="uid://cx44bjuxlhq06"] [gd_scene load_steps=5 format=3 uid="uid://cx44bjuxlhq06"]
[ext_resource type="PackedScene" uid="uid://buxxa2rq7s8eg" path="res://Models/buildings/building_01.2.glb" id="1_sy5sk"] [ext_resource type="PackedScene" uid="uid://buxxa2rq7s8eg" path="res://Models/buildings/building_01.2.glb" id="1_sy5sk"]
[ext_resource type="Texture2D" uid="uid://vnlqr1ob2tss" path="res://Textures/building_02.png" id="2_ns75r"] [ext_resource type="Texture2D" uid="uid://vnlqr1ob2tss" path="res://Textures/building_02.png" id="2_ns75r"]
@ -6,7 +6,16 @@
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_ktg7d"] [sub_resource type="StandardMaterial3D" id="StandardMaterial3D_ktg7d"]
albedo_texture = ExtResource("2_ns75r") albedo_texture = ExtResource("2_ns75r")
[sub_resource type="BoxShape3D" id="BoxShape3D_wy6bt"]
size = Vector3(0.377897, 0.527655, 0.362437)
[node name="building_01_2" instance=ExtResource("1_sy5sk")] [node name="building_01_2" instance=ExtResource("1_sy5sk")]
[node name="node_id4" parent="root" index="0"] [node name="node_id4" parent="root" index="0"]
surface_material_override/0 = SubResource("StandardMaterial3D_ktg7d") surface_material_override/0 = SubResource("StandardMaterial3D_ktg7d")
[node name="StaticBody3D" type="StaticBody3D" parent="." index="1"]
[node name="CollisionShape3D" type="CollisionShape3D" parent="StaticBody3D" index="0"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.00178906, 0.251368)
shape = SubResource("BoxShape3D_wy6bt")

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=4 format=3 uid="uid://bm65tvb4irjqw"] [gd_scene load_steps=5 format=3 uid="uid://bm65tvb4irjqw"]
[ext_resource type="PackedScene" uid="uid://dgm33vy6bq45y" path="res://Models/buildings/building_01.3.glb" id="1_6oij5"] [ext_resource type="PackedScene" uid="uid://dgm33vy6bq45y" path="res://Models/buildings/building_01.3.glb" id="1_6oij5"]
[ext_resource type="Texture2D" uid="uid://cew7em3xjhrbo" path="res://Textures/building_03.png" id="2_qgmwq"] [ext_resource type="Texture2D" uid="uid://cew7em3xjhrbo" path="res://Textures/building_03.png" id="2_qgmwq"]
@ -6,7 +6,16 @@
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_h48n6"] [sub_resource type="StandardMaterial3D" id="StandardMaterial3D_h48n6"]
albedo_texture = ExtResource("2_qgmwq") albedo_texture = ExtResource("2_qgmwq")
[sub_resource type="BoxShape3D" id="BoxShape3D_t3xdb"]
size = Vector3(0.366655, 0.527655, 0.367689)
[node name="building_01_3" instance=ExtResource("1_6oij5")] [node name="building_01_3" instance=ExtResource("1_6oij5")]
[node name="node_id4" parent="root" index="0"] [node name="node_id4" parent="root" index="0"]
surface_material_override/0 = SubResource("StandardMaterial3D_h48n6") surface_material_override/0 = SubResource("StandardMaterial3D_h48n6")
[node name="StaticBody3D" type="StaticBody3D" parent="root" index="1"]
[node name="CollisionShape3D" type="CollisionShape3D" parent="root/StaticBody3D" index="0"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0.251368)
shape = SubResource("BoxShape3D_t3xdb")

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=4 format=3 uid="uid://tky3cco2k7v7"] [gd_scene load_steps=5 format=3 uid="uid://tky3cco2k7v7"]
[ext_resource type="PackedScene" uid="uid://ct2lgbtpp3wp" path="res://Models/buildings/building_01.4.glb" id="1_xd1sg"] [ext_resource type="PackedScene" uid="uid://ct2lgbtpp3wp" path="res://Models/buildings/building_01.4.glb" id="1_xd1sg"]
[ext_resource type="Texture2D" uid="uid://ckmnisf86xgdu" path="res://Textures/building_05.png" id="2_1ortp"] [ext_resource type="Texture2D" uid="uid://ckmnisf86xgdu" path="res://Textures/building_05.png" id="2_1ortp"]
@ -6,7 +6,16 @@
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_3mjbs"] [sub_resource type="StandardMaterial3D" id="StandardMaterial3D_3mjbs"]
albedo_texture = ExtResource("2_1ortp") albedo_texture = ExtResource("2_1ortp")
[sub_resource type="BoxShape3D" id="BoxShape3D_6nnc6"]
size = Vector3(0.53466, 0.527655, 0.526273)
[node name="building_01_4" instance=ExtResource("1_xd1sg")] [node name="building_01_4" instance=ExtResource("1_xd1sg")]
[node name="node_id4" parent="root" index="0"] [node name="node_id4" parent="root" index="0"]
surface_material_override/0 = SubResource("StandardMaterial3D_3mjbs") surface_material_override/0 = SubResource("StandardMaterial3D_3mjbs")
[node name="StaticBody3D" type="StaticBody3D" parent="root" index="1"]
[node name="CollisionShape3D" type="CollisionShape3D" parent="root/StaticBody3D" index="0"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0.251368)
shape = SubResource("BoxShape3D_6nnc6")

View File

@ -1,92 +1,2 @@
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.
func _ready():
pass
# 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()
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"
"walk":
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"
"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 _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()

18
godot/cultist.gd Normal file
View File

@ -0,0 +1,18 @@
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())

View File

@ -1,5 +1,6 @@
[gd_scene load_steps=5 format=3 uid="uid://e0s4phx2jiit"] [gd_scene load_steps=7 format=3 uid="uid://e0s4phx2jiit"]
[ext_resource type="Script" path="res://cultist.gd" id="1_k6djk"]
[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="CapsuleShape3D" id="CapsuleShape3D_y0hcm"] [sub_resource type="CapsuleShape3D" id="CapsuleShape3D_y0hcm"]
@ -10,12 +11,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_rypky"]
radius = 20.0
[node name="RigidBody3D" type="RigidBody3D" parent="."] [node name="Cultist" type="CharacterBody3D"]
script = ExtResource("1_k6djk")
[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_rypky")
[connection signal="body_entered" from="Area3D" to="." method="_on_area_3d_body_entered"]

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, 0) transform = Transform3D(0.1, 0, 0, 0, 0.1, 0, 0, 0, 0.1, 0, 0.0469455, 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

@ -3,11 +3,97 @@ 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.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()