First commit
This commit is contained in:
1
icon.svg
Normal file
1
icon.svg
Normal file
@@ -0,0 +1 @@
|
|||||||
|
<svg height="128" width="128" xmlns="http://www.w3.org/2000/svg"><rect fill="#363d52" height="128" rx="2" width="128" y="0" x="0"/><circle cx="64" cy="64" fill="#478cbf" r="32"/><path d="M46.8 77.2l12.4-44.1a12.8 12.8 0 0 1 24-.5l13 44.6" fill="none" stroke="#fff" stroke-linecap="round" stroke-width="8"/></svg>
|
||||||
|
After Width: | Height: | Size: 313 B |
25
project.godot
Normal file
25
project.godot
Normal file
@@ -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"
|
||||||
43
scenes/Main.tscn
Normal file
43
scenes/Main.tscn
Normal file
@@ -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)
|
||||||
15
scenes/Player.tscn
Normal file
15
scenes/Player.tscn
Normal file
@@ -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)
|
||||||
68
scripts/Player.gd
Normal file
68
scripts/Player.gd
Normal file
@@ -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()
|
||||||
Reference in New Issue
Block a user