From 5e3675d5c9c3625a6a4a6762c9478905454b7866 Mon Sep 17 00:00:00 2001 From: Quantum Date: Mon, 2 Oct 2023 17:28:55 -0400 Subject: [PATCH] Flashlight / cleanup --- Player.gd | 30 +++++++++++++++++++++--------- Player.tscn | 8 ++++++++ assets | 2 +- project.godot | 5 +++++ 4 files changed, 35 insertions(+), 10 deletions(-) diff --git a/Player.gd b/Player.gd index 6a18338..1c0b4b7 100644 --- a/Player.gd +++ b/Player.gd @@ -18,7 +18,13 @@ const JUMP_SPEED = 270 * QUAKE # const MAX_SLOPE_ANGLE = 30https://www.youtube.com/watch?v=v3zT3Z5apaM @onready -var camera = $CSGMesh3D/Camera3D +var _camera = $CSGMesh3D/Camera3D +@onready +var _ball = $Ball +@onready +var _collider = $CollisionShape3D +@onready +var _flashlight: SpotLight3D = $Flashlight var _paused = false var _noclip = false @@ -50,7 +56,7 @@ func _physics_process(delta): smove *= 2.0 var wishvel = Vector3() - var cam_xform: Transform3D = camera.get_global_transform() + var cam_xform: Transform3D = _camera.get_global_transform() var cam_basis: Basis = cam_xform.basis wishvel = cam_basis.z * fmove + cam_basis.x * smove @@ -83,7 +89,7 @@ func _physics_process(delta): velocity = vel move_and_slide() - $Ball.global_position = camera.global_position - camera.global_transform.basis.z * 2.0 + _ball.global_position = _camera.global_position - _camera.global_transform.basis.z * 2.0 func _apply_friction(vel: Vector3, delta: float): var speed = sqrt(vel.x ** 2 + vel.z ** 2) @@ -150,20 +156,26 @@ func _input(event): if event.is_action_pressed('noclip'): _noclip = not _noclip if _noclip: - $CollisionShape3D.disabled = true + _collider.disabled = true else: - $CollisionShape3D.disabled = false + _collider.disabled = false + + if event.is_action_pressed('flashlight'): + _flashlight.visible = not _flashlight.visible - # Check for mouse motion input + # Camera if event is InputEventMouseMotion: rotation.y += -event.relative.x * 0.005 - camera.rotation.x += -event.relative.y * 0.005 - camera.rotation.x = clamp(camera.rotation.x, deg_to_rad(-70), deg_to_rad(70)) + _camera.rotation.x += -event.relative.y * 0.005 + _camera.rotation.x = clamp(_camera.rotation.x, deg_to_rad(-70), deg_to_rad(70)) + + # Rotate flashlight + _flashlight.rotation.x = _camera.rotation.x if event.is_action_pressed("interact"): var space_state = get_world_3d().direct_space_state # use global coordinates, not local to node - var query = PhysicsRayQueryParameters3D.create(camera.global_position, $Ball.global_position) + var query = PhysicsRayQueryParameters3D.create(_camera.global_position, _ball.global_position) # Don't collide with ourselves query.exclude = [self] var result = space_state.intersect_ray(query) diff --git a/Player.tscn b/Player.tscn index 6489255..4a46995 100644 --- a/Player.tscn +++ b/Player.tscn @@ -24,3 +24,11 @@ size = 6.683 [node name="Ball" type="CSGSphere3D" parent="."] radius = 0.1 + +[node name="Flashlight" type="SpotLight3D" parent="."] +transform = Transform3D(1, 0, 0, 0, 0.990246, 0.139329, 0, -0.139329, 0.990246, 0, 1.5, -0.4) +light_color = Color(1, 1, 0.768627, 1) +shadow_enabled = true +distance_fade_enabled = true +spot_range = 23.1777 +spot_angle = 40.1352 diff --git a/assets b/assets index 619feff..d1130c6 160000 --- a/assets +++ b/assets @@ -1 +1 @@ -Subproject commit 619feff3dcd1829bd0cf21a09414ac7e19beed2d +Subproject commit d1130c67c3da7ab7e2c774e51d77031e5f811569 diff --git a/project.godot b/project.godot index 8189cd3..e65fd7b 100644 --- a/project.godot +++ b/project.godot @@ -62,3 +62,8 @@ noclip={ "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":86,"key_label":0,"unicode":118,"echo":false,"script":null) ] } +flashlight={ +"deadzone": 0.5, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":70,"key_label":0,"unicode":102,"echo":false,"script":null) +] +}