Flashlight / cleanup

This commit is contained in:
Thomas Muller 2023-10-02 17:28:55 -04:00
parent 0879af0252
commit 5e3675d5c9
4 changed files with 35 additions and 10 deletions

View file

@ -18,7 +18,13 @@ const JUMP_SPEED = 270 * QUAKE
# const MAX_SLOPE_ANGLE = 30https://www.youtube.com/watch?v=v3zT3Z5apaM # const MAX_SLOPE_ANGLE = 30https://www.youtube.com/watch?v=v3zT3Z5apaM
@onready @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 _paused = false
var _noclip = false var _noclip = false
@ -50,7 +56,7 @@ func _physics_process(delta):
smove *= 2.0 smove *= 2.0
var wishvel = Vector3() 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 var cam_basis: Basis = cam_xform.basis
wishvel = cam_basis.z * fmove + cam_basis.x * smove wishvel = cam_basis.z * fmove + cam_basis.x * smove
@ -83,7 +89,7 @@ func _physics_process(delta):
velocity = vel velocity = vel
move_and_slide() 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): func _apply_friction(vel: Vector3, delta: float):
var speed = sqrt(vel.x ** 2 + vel.z ** 2) var speed = sqrt(vel.x ** 2 + vel.z ** 2)
@ -150,20 +156,26 @@ func _input(event):
if event.is_action_pressed('noclip'): if event.is_action_pressed('noclip'):
_noclip = not _noclip _noclip = not _noclip
if _noclip: if _noclip:
$CollisionShape3D.disabled = true _collider.disabled = true
else: 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: if event is InputEventMouseMotion:
rotation.y += -event.relative.x * 0.005 rotation.y += -event.relative.x * 0.005
camera.rotation.x += -event.relative.y * 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 = 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"): if event.is_action_pressed("interact"):
var space_state = get_world_3d().direct_space_state var space_state = get_world_3d().direct_space_state
# use global coordinates, not local to node # 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 # Don't collide with ourselves
query.exclude = [self] query.exclude = [self]
var result = space_state.intersect_ray(query) var result = space_state.intersect_ray(query)

View file

@ -24,3 +24,11 @@ size = 6.683
[node name="Ball" type="CSGSphere3D" parent="."] [node name="Ball" type="CSGSphere3D" parent="."]
radius = 0.1 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

2
assets

@ -1 +1 @@
Subproject commit 619feff3dcd1829bd0cf21a09414ac7e19beed2d Subproject commit d1130c67c3da7ab7e2c774e51d77031e5f811569

View file

@ -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) "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)
]
}