From bbbb8db7a000051b72982a711f3a0cc17b60aad2 Mon Sep 17 00:00:00 2001 From: eliazarw Date: Thu, 19 Mar 2026 14:13:01 -0400 Subject: [PATCH] First commit --- icon.svg | 1 + project.godot | 25 +++++++++++++++++ scenes/Main.tscn | 43 +++++++++++++++++++++++++++++ scenes/Player.tscn | 15 ++++++++++ scripts/Player.gd | 68 ++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 152 insertions(+) create mode 100644 icon.svg create mode 100644 project.godot create mode 100644 scenes/Main.tscn create mode 100644 scenes/Player.tscn create mode 100644 scripts/Player.gd diff --git a/icon.svg b/icon.svg new file mode 100644 index 0000000..78bda2f --- /dev/null +++ b/icon.svg @@ -0,0 +1 @@ + diff --git a/project.godot b/project.godot new file mode 100644 index 0000000..77a1d4a --- /dev/null +++ b/project.godot @@ -0,0 +1,25 @@ +config_version=5 + +[application] + +config/name="Restaurant (4.0)" +run/main_scene="res://scenes/Main.tscn" +config/features=PackedStringArray("4.0", "Forward Plus") +config/icon="res://icon.svg" + +[display] + +window/size/viewport_width=1280 +window/size/viewport_height=720 + +[dotnet] + +project/assembly_name="Restaurant" + +[physics] + +common/physics_ticks_per_second=60 + +[rendering] + +renderer/rendering_method="forward_plus" diff --git a/scenes/Main.tscn b/scenes/Main.tscn new file mode 100644 index 0000000..7bae898 --- /dev/null +++ b/scenes/Main.tscn @@ -0,0 +1,43 @@ +[gd_scene load_steps=7 format=3] + +[ext_resource type="PackedScene" path="res://scenes/Player.tscn" id="1_player"] + +[sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_1"] +sky_horizon_color = Color(0.64625, 0.65575, 0.67075, 1) +ground_horizon_color = Color(0.64625, 0.65575, 0.67075, 1) + +[sub_resource type="Sky" id="Sky_1"] +sky_material = SubResource("ProceduralSkyMaterial_1") + +[sub_resource type="Environment" id="Environment_1"] +background_mode = 2 +sky = SubResource("Sky_1") +tonemap_mode = 2 +glow_enabled = true + +[sub_resource type="BoxMesh" id="BoxMesh_ground"] +size = Vector3(20, 1, 20) + +[sub_resource type="BoxShape3D" id="BoxShape3D_ground"] +size = Vector3(20, 1, 20) + +[node name="Main" type="Node3D"] + +[node name="WorldEnvironment" type="WorldEnvironment" parent="."] +environment = SubResource("Environment_1") + +[node name="DirectionalLight3D" type="DirectionalLight3D" parent="."] +transform = Transform3D(-0.866025, -0.433013, 0.25, 0, 0.5, 0.866025, -0.5, 0.75, -0.433013, 0, 0, 0) +shadow_enabled = true + +[node name="Ground" type="StaticBody3D" parent="."] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.5, 0) + +[node name="MeshInstance3D" type="MeshInstance3D" parent="Ground"] +mesh = SubResource("BoxMesh_ground") + +[node name="CollisionShape3D" type="CollisionShape3D" parent="Ground"] +shape = SubResource("BoxShape3D_ground") + +[node name="Player" parent="." instance=ExtResource("1_player")] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0) diff --git a/scenes/Player.tscn b/scenes/Player.tscn new file mode 100644 index 0000000..55d1515 --- /dev/null +++ b/scenes/Player.tscn @@ -0,0 +1,15 @@ +[gd_scene load_steps=3 format=3] + +[ext_resource type="Script" path="res://scripts/Player.gd" id="1_script"] + +[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_player"] + +[node name="Player" type="CharacterBody3D"] +script = ExtResource("1_script") + +[node name="CollisionShape3D" type="CollisionShape3D" parent="."] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0) +shape = SubResource("CapsuleShape3D_player") + +[node name="Camera3D" type="Camera3D" parent="."] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.7, 0) diff --git a/scripts/Player.gd b/scripts/Player.gd new file mode 100644 index 0000000..44a14e4 --- /dev/null +++ b/scripts/Player.gd @@ -0,0 +1,68 @@ +extends CharacterBody3D + +## Simple First-Person Player Controller +## +## Features: +## - WASD Movement with acceleration/deceleration +## - Gravity +## - Mouse Look +## +## Note: Modify `MOUSE_SENSITIVITY` and `SPEED` to tune gameplay. + +# Configuration +const SPEED = 5.0 +const SPRINT_SPEED = 8.0 +const JUMP_VELOCITY = 4.5 +const ACCELERATION = 10.0 +const FRICTION = 10.0 +const GRAVITY = 9.8 +const MOUSE_SENSITIVITY = 0.003 + +# References +@onready var camera = $Camera3D + +func _ready(): + # Capture mouse cursor for gameplay + Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED) + +func _unhandled_input(event): + # Handle Mouse Look + if event is InputEventMouseMotion: + rotate_y(-event.relative.x * MOUSE_SENSITIVITY) + camera.rotate_x(-event.relative.y * MOUSE_SENSITIVITY) + # Clamp view to prevent flipping over + camera.rotation.x = clamp(camera.rotation.x, deg_to_rad(-90), deg_to_rad(90)) + + # Toggle Mouse Capture (Escape to exit) + if event.is_action_pressed("ui_cancel"): + if Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED: + Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE) + else: + Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED) + +func _physics_process(delta): + # Add 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 Input Direction (WASD / Arrows) + # "ui_up", "ui_down", "ui_left", "ui_right" are default Godot 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() + + # Determine current speed (Sprint support optional) + var current_speed = SPRINT_SPEED if Input.is_key_pressed(KEY_SHIFT) else SPEED + + # Apply Movement with Acceleration/Friction + if direction: + velocity.x = move_toward(velocity.x, direction.x * current_speed, ACCELERATION * delta) + velocity.z = move_toward(velocity.z, direction.z * current_speed, ACCELERATION * delta) + else: + velocity.x = move_toward(velocity.x, 0, FRICTION * delta) + velocity.z = move_toward(velocity.z, 0, FRICTION * delta) + + move_and_slide()