Godot Version
4.2.1 (Steam)
Question
I have a SpotLight3D that acts as a flashlight. it uses a GradientTexture2D as the projector texture, and it points to wherever the mouse is facing using this code (the camera is stationary):
extends SpotLight3D
@onready var SpaceState = self.get_world_3d().direct_space_state
@onready var RayOrigin = $".".position
@onready var RayEnd = Vector3()
func _input(event):
if (event is InputEventMouseMotion and $"../Status/OfficeState".get("flashlight") == 1) or (event is InputEventKey and Input.is_action_just_pressed("Flashlight")):
var mouse_offset = get_viewport().get_mouse_position()
RayEnd = RayOrigin + $"../SpotLight3D/Camera3D".project_ray_normal(mouse_offset) * 10000
var params = PhysicsRayQueryParameters3D.new()
params.to = RayOrigin
params.from = RayEnd
params.collide_with_areas = true
params.hit_back_faces = true
#params.collision_mask = 1
var intersection = SpaceState.intersect_ray(params)
if not intersection.is_empty():
var pos = intersection["position"]
$".".look_at(pos)
For some reason whenever I make the “visible” parameter true for the first time after running the game, it freezes for about 5 seconds, and lags a bit more after.
It works perfectly fine every subsequent time the visible flag is checked, just not the first.
please help, this i really doing my head in