feat: Make variables for sizes

This commit is contained in:
Dusk 2026-03-03 17:10:20 +01:00
parent 549d0c82db
commit 1bc9f30c44
6 changed files with 52 additions and 42 deletions

View File

@ -3,9 +3,13 @@ extends Node3D
var exits: Array = [false, false, false, false] var exits: Array = [false, false, false, false]
const STREET_WIDTH: float = 40
func _ready() -> void: func _ready() -> void:
pass $Mesh.mesh.size.x = Global.chunk_size
$Mesh.mesh.size.y = Global.chunk_size
#exits = [ #exits = [
#randi() % 2 == 0, #randi() % 2 == 0,
#randi() % 2 == 0, #randi() % 2 == 0,
@ -26,12 +30,12 @@ func update() -> void:
#$n.position.y = 1 #$n.position.y = 1
var vertices = PackedVector3Array() var vertices = PackedVector3Array()
vertices.push_back(Vector3(-5, 0.5, -50)) vertices.push_back(Vector3(-STREET_WIDTH/2, 0.5, -Global.chunk_size/2))
vertices.push_back(Vector3(5, 0.5, -50)) vertices.push_back(Vector3(STREET_WIDTH/2 , 0.5, -Global.chunk_size/2))
vertices.push_back(Vector3(-5, 0.5, 0)) vertices.push_back(Vector3(-STREET_WIDTH/2, 0.5, 0))
vertices.push_back(Vector3(5, 0.5, -50)) vertices.push_back(Vector3(STREET_WIDTH/2, 0.5, -Global.chunk_size/2))
vertices.push_back(Vector3(5, 0.5, 0)) vertices.push_back(Vector3(STREET_WIDTH/2, 0.5, 0))
vertices.push_back(Vector3(-5, 0.5, 0)) vertices.push_back(Vector3(-STREET_WIDTH/2, 0.5, 0))
# Initialize the ArrayMesh. # Initialize the ArrayMesh.
var arr_mesh = ArrayMesh.new() var arr_mesh = ArrayMesh.new()
@ -47,12 +51,12 @@ func update() -> void:
#$s.position.y = 1 #$s.position.y = 1
var vertices = PackedVector3Array() var vertices = PackedVector3Array()
vertices.push_back(Vector3(-5, 0.5, 0)) vertices.push_back(Vector3(-STREET_WIDTH/2, 0.5, 0))
vertices.push_back(Vector3(5, 0.5, 0)) vertices.push_back(Vector3(STREET_WIDTH/2, 0.5, 0))
vertices.push_back(Vector3(-5, 0.5, 50)) vertices.push_back(Vector3(-STREET_WIDTH/2, 0.5, Global.chunk_size/2))
vertices.push_back(Vector3(5, 0.5, 0)) vertices.push_back(Vector3(STREET_WIDTH/2, 0.5, 0))
vertices.push_back(Vector3(5, 0.5, 50)) vertices.push_back(Vector3(STREET_WIDTH/2, 0.5, Global.chunk_size/2))
vertices.push_back(Vector3(-5, 0.5, 50)) vertices.push_back(Vector3(-STREET_WIDTH/2, 0.5, Global.chunk_size/2))
# Initialize the ArrayMesh. # Initialize the ArrayMesh.
var arr_mesh = ArrayMesh.new() var arr_mesh = ArrayMesh.new()
@ -68,12 +72,12 @@ func update() -> void:
#$w.position.y = 1 #$w.position.y = 1
var vertices = PackedVector3Array() var vertices = PackedVector3Array()
vertices.push_back(Vector3(-50, 0.5, -5)) vertices.push_back(Vector3(-Global.chunk_size/2, 0.5, -STREET_WIDTH/2))
vertices.push_back(Vector3(0, 0.5, -5)) vertices.push_back(Vector3(0, 0.5, -STREET_WIDTH/2))
vertices.push_back(Vector3(-50, 0.5, 5)) vertices.push_back(Vector3(-Global.chunk_size/2, 0.5, STREET_WIDTH/2))
vertices.push_back(Vector3(0, 0.5, -5)) vertices.push_back(Vector3(0, 0.5, -STREET_WIDTH/2))
vertices.push_back(Vector3(0, 0.5, 5)) vertices.push_back(Vector3(0, 0.5, STREET_WIDTH/2))
vertices.push_back(Vector3(-50, 0.5, 5)) vertices.push_back(Vector3(-Global.chunk_size/2, 0.5, STREET_WIDTH/2))
# Initialize the ArrayMesh. # Initialize the ArrayMesh.
var arr_mesh = ArrayMesh.new() var arr_mesh = ArrayMesh.new()
@ -89,12 +93,12 @@ func update() -> void:
#$e.position.y = 1 #$e.position.y = 1
var vertices = PackedVector3Array() var vertices = PackedVector3Array()
vertices.push_back(Vector3(0, 0.5, -5)) vertices.push_back(Vector3(0, 0.5, -STREET_WIDTH/2))
vertices.push_back(Vector3(50, 0.5, -5)) vertices.push_back(Vector3(Global.chunk_size/2, 0.5, -STREET_WIDTH/2))
vertices.push_back(Vector3(0, 0.5, 5)) vertices.push_back(Vector3(0, 0.5, STREET_WIDTH/2))
vertices.push_back(Vector3(50, 0.5, -5)) vertices.push_back(Vector3(Global.chunk_size/2, 0.5, -STREET_WIDTH/2))
vertices.push_back(Vector3(50, 0.5, 5)) vertices.push_back(Vector3(Global.chunk_size/2, 0.5, STREET_WIDTH/2))
vertices.push_back(Vector3(0, 0.5, 5)) vertices.push_back(Vector3(0, 0.5, STREET_WIDTH/2))
# Initialize the ArrayMesh. # Initialize the ArrayMesh.
var arr_mesh = ArrayMesh.new() var arr_mesh = ArrayMesh.new()
@ -110,7 +114,7 @@ func update() -> void:
var center_mesh = MeshInstance3D.new() var center_mesh = MeshInstance3D.new()
center_mesh.position = Vector3(0,0.6,0) center_mesh.position = Vector3(0,0.6,0)
center_mesh.mesh = PlaneMesh.new() center_mesh.mesh = PlaneMesh.new()
center_mesh.mesh.size = Vector2(10,10) center_mesh.mesh.size = Vector2(STREET_WIDTH,STREET_WIDTH)
add_child(center_mesh) add_child(center_mesh)
i += 1 i += 1

2
global.gd Normal file
View File

@ -0,0 +1,2 @@
extends Node
var chunk_size: float = 150

View File

@ -3,6 +3,8 @@ extends Node3D
@export var dimension: int = 5 @export var dimension: int = 5
@export var path_count: int = 5 @export var path_count: int = 5
@export var ped_spawn_rate: int = 60
var pedestrian_scene = preload("res://pedestrian.tscn") var pedestrian_scene = preload("res://pedestrian.tscn")
func dir_to_vector(dir: int) -> Vector2i: func dir_to_vector(dir: int) -> Vector2i:
@ -32,11 +34,11 @@ func _ready() -> void:
var station = Vector2i(randi() % dimension, 0) var station = Vector2i(randi() % dimension, 0)
var spawn = Vector2i(dimension - station.x - 1, dimension - 1) var spawn = Vector2i(dimension - station.x - 1, dimension - 1)
$Player.position.x = station.x * 100 $Player.position.x = station.x * Global.chunk_size
$Player.position.z = station.y * 100 $Player.position.z = station.y * Global.chunk_size
$Pedestrian.position.x = station.x * 100 $Pedestrian.position.x = station.x * Global.chunk_size
$Pedestrian.position.z = station.y * 100 $Pedestrian.position.z = station.y * Global.chunk_size
var paths: Array = [] var paths: Array = []
for path_idx in range(path_count): for path_idx in range(path_count):
@ -69,7 +71,7 @@ func _ready() -> void:
var row: Array var row: Array
for y in range(dimension): for y in range(dimension):
var new_chunk = chunk_scn.instantiate() var new_chunk = chunk_scn.instantiate()
new_chunk.position = Vector3(x * 101, 0, y * 101) new_chunk.position = Vector3(x * Global.chunk_size+1, 0, y * Global.chunk_size+1)
row.append(new_chunk) row.append(new_chunk)
add_child(new_chunk) add_child(new_chunk)
chunks.append(row) chunks.append(row)
@ -92,7 +94,7 @@ func _process(delta: float) -> void:
var spawn_radius = $Player/SpawnArea/Collision.shape.radius + randf_range(-5, 5) var spawn_radius = $Player/SpawnArea/Collision.shape.radius + randf_range(-5, 5)
var rand_unit_vec = Vector3.RIGHT.rotated(Vector3.UP, randf() * TAU) var rand_unit_vec = Vector3.RIGHT.rotated(Vector3.UP, randf() * TAU)
var ped_pos = $Player.position + rand_unit_vec * spawn_radius var ped_pos = $Player.position + rand_unit_vec * spawn_radius
if (randi() % 60 == 5): if (randi() % ped_spawn_rate == 0):
print("Pedestrian at ", ped_pos) print("Pedestrian at ", ped_pos)
var new_ped = pedestrian_scene.instantiate() var new_ped = pedestrian_scene.instantiate()
add_child(new_ped) add_child(new_ped)

View File

@ -3,7 +3,6 @@
[ext_resource type="Script" uid="uid://dj0cgqed5n3ys" path="res://level.gd" id="1_0b4ue"] [ext_resource type="Script" uid="uid://dj0cgqed5n3ys" path="res://level.gd" id="1_0b4ue"]
[ext_resource type="PackedScene" uid="uid://cmb3b7xrlboy3" path="res://player.tscn" id="1_u52ul"] [ext_resource type="PackedScene" uid="uid://cmb3b7xrlboy3" path="res://player.tscn" id="1_u52ul"]
[ext_resource type="Script" uid="uid://b5ebibi08tjvd" path="res://camera_3d.gd" id="2_vonw3"] [ext_resource type="Script" uid="uid://b5ebibi08tjvd" path="res://camera_3d.gd" id="2_vonw3"]
[ext_resource type="PackedScene" uid="uid://cqbu5r5pmnhc" path="res://chunk.tscn" id="3_f2txt"]
[ext_resource type="PackedScene" uid="uid://c76lhqe6dqq50" path="res://pedestrian.tscn" id="4_f2txt"] [ext_resource type="PackedScene" uid="uid://c76lhqe6dqq50" path="res://pedestrian.tscn" id="4_f2txt"]
[sub_resource type="Environment" id="Environment_vonw3"] [sub_resource type="Environment" id="Environment_vonw3"]
@ -25,9 +24,6 @@ environment = SubResource("Environment_vonw3")
[node name="Player" parent="." unique_id=1536233267 instance=ExtResource("1_u52ul")] [node name="Player" parent="." unique_id=1536233267 instance=ExtResource("1_u52ul")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.8361101, 0) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.8361101, 0)
[node name="Chunk" parent="." unique_id=731620195 instance=ExtResource("3_f2txt")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.08452606, -3.8146973e-06, 0.120262146)
[node name="MeshInstance3D2" type="MeshInstance3D" parent="." unique_id=306152407] [node name="MeshInstance3D2" type="MeshInstance3D" parent="." unique_id=306152407]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -11.830486, 7.5, -23.788916) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -11.830486, 7.5, -23.788916)
mesh = SubResource("BoxMesh_vonw3") mesh = SubResource("BoxMesh_vonw3")
@ -40,7 +36,7 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -11.874296, 3.5, -11.78)
mesh = SubResource("BoxMesh_oi3di") mesh = SubResource("BoxMesh_oi3di")
[node name="Camera3D" type="Camera3D" parent="." unique_id=2083164402] [node name="Camera3D" type="Camera3D" parent="." unique_id=2083164402]
transform = Transform3D(1, 0, 0, 0, -4.371139e-08, 1, 0, -1, -4.371139e-08, 0, 113.43584, 0) transform = Transform3D(1, 0, 0, 0, -4.371139e-08, 1, 0, -1, -4.371139e-08, 0, 47.751747, 0)
current = true current = true
fov = 55.0 fov = 55.0
script = ExtResource("2_vonw3") script = ExtResource("2_vonw3")

View File

@ -1,12 +1,14 @@
extends StaticBody3D extends StaticBody3D
@onready var x_movement = randi() % 10 var movement_rate = 200
@onready var z_movement = randi() % 10
@onready var x_movement = randi_range(-10, 10)
@onready var z_movement = randi_range(-10, 10)
func _process(delta: float) -> void: func _process(delta: float) -> void:
if (randi() % 80) == 1: if (randi() % movement_rate) == 1:
x_movement = randi() % 10 x_movement = randi_range(-10, 10)
z_movement = randi() % 10 z_movement = randi_range(-10, 10)
randomize() randomize()
move_and_collide(Vector3(x_movement, 0, z_movement) * delta) move_and_collide(Vector3(x_movement, 0, z_movement) * delta)

View File

@ -15,6 +15,10 @@ run/main_scene="uid://dxap1hj0okhli"
config/features=PackedStringArray("4.6", "GL Compatibility") config/features=PackedStringArray("4.6", "GL Compatibility")
config/icon="res://icon.svg" config/icon="res://icon.svg"
[autoload]
Global="*uid://ca3n3ljnvvdil"
[input] [input]
player_move_left={ player_move_left={