hurrmmm/godot/control_scheme/controller.gd

64 lines
1.8 KiB
GDScript

extends Node3D
@export var camera: Camera3D
@export var target: Node3D
@export var sensitivity := 0.01
func _input(event):
if event is InputEventMouseMotion:
rotate_view(event.relative*sensitivity)
func _process(_delta):
transform.origin = target.global_position
camera.global_position = %camera_spot.global_position
camera.look_at(target.global_position)
func rotate_view(amount: Vector2):
rotate_y(-amount.x)
%rotate_helper.rotate_z(amount.y)
%rotate_helper.rotation_degrees.z = clampf(%rotate_helper.rotation_degrees.z, -77, 77)
func set_target(node: Node3D, should_unset=true):
if target != null and should_unset:
pass
var old_material_props = null
func change_material(mesh: MeshInstance3D):
if old_material_props != null:
push_error("UH OOH!!! 628")
old_material_props = []
for i in range(mesh.get_surface_override_material_count()):
var mat := mesh.get_active_material(i)
if mat is BaseMaterial3D:
old_material_props.append(mat.depth_draw_mode)
mat.depth_draw_mode = BaseMaterial3D.DEPTH_DRAW_DISABLED
push_next_pass(mat, preload("control_target_overlay.material"))
else:
old_material_props.append(null)
push_error("Don't know how to handle shader material for", mesh)
func unchange_material(mesh: MeshInstance3D):
if old_material_props == null:
push_error("UH OOH!!! 629")
for i in range(mesh.get_surface_override_material_count()):
var mat := mesh.get_active_material(i)
if mat is BaseMaterial3D:
mat.depth_draw_mode = old_material_props[i]
pop_next_pass(mat)
else:
push_error("Don't know how to handle shader material for", mesh)
func push_next_pass(m: Material, with: Material):
if m.next_pass != null:
push_next_pass(m.next_pass, with)
else:
m.next_pass = with
func pop_next_pass(m: Material):
if m == null:
return true
if pop_next_pass(m.next_pass):
m.next_pass = null
return false