Added raycast
Added making object interactable Added slider + knob
This commit is contained in:
35
scripts/Slider1.gd
Normal file
35
scripts/Slider1.gd
Normal file
@@ -0,0 +1,35 @@
|
||||
extends StaticBody3D
|
||||
|
||||
|
||||
@export var slider_length: float = 0.5
|
||||
@export var angle_degrees: float = 20.0
|
||||
@export var scroll_sensitivity: float = 0.025
|
||||
@onready var knob : MeshInstance3D = $Slider/Knob
|
||||
|
||||
var knob_position : float = 0.0
|
||||
var interacting : bool = false
|
||||
|
||||
func _ready() -> void:
|
||||
print("ready!")
|
||||
update_knob_position()
|
||||
|
||||
func _process(_delta : float) -> void:
|
||||
if interacting:
|
||||
if Input.is_action_just_pressed("scroll_up"):
|
||||
knob_position = clamp(knob_position + scroll_sensitivity, 0.0, 1.0)
|
||||
update_knob_position()
|
||||
elif Input.is_action_just_pressed("scroll_down"):
|
||||
knob_position = clamp(knob_position - scroll_sensitivity, 0.0, 1.0)
|
||||
update_knob_position()
|
||||
|
||||
func update_knob_position() -> void:
|
||||
var start_position : Vector3 = Vector3(0, 0.04, slider_length / 2)
|
||||
var end_position : Vector3 = Vector3(0, 0.04, -slider_length / 2)
|
||||
|
||||
var knob_world_position : Vector3 = start_position.lerp(end_position, knob_position)
|
||||
knob.position = knob_world_position
|
||||
print(knob_position)
|
||||
print(knob_world_position)
|
||||
|
||||
func make_interactable(interactable : bool) -> void:
|
||||
interacting = interactable
|
||||
Reference in New Issue
Block a user