Compare commits

..

No commits in common. "3fa504f25a3bf9bfbd93f922913134df56499e33" and "86b29ec4768e11c758cc1f74acdfec99bf63ef4f" have entirely different histories.

5 changed files with 27 additions and 50 deletions

View File

@ -7,47 +7,25 @@ var target: Targetable = null
@export var charge_time := 1.7 @export var charge_time := 1.7
@export var min_charge := 0.2 @export var min_charge := 0.2
var camera_tweening = false
func _ready(): func _ready():
set_target(initial_target, false) set_target(initial_target)
ControllerEventBus.billiard_touched_billiard.connect(_on_billiard_touched_billiard)
func _on_billiard_touched_billiard(who: Billiard, touched: Billiard):
var who_target = Targetable.is_targetable(who)
if who_target != target or who.can_hit:
return
set_target(touched)
ControllerEventBus.new_target.emit(touched)
func get_charge(): func get_charge():
return %radial_ui.charge_amount return %radial_ui.charge_amount
func _input(event): func _input(event):
var billiard := target.get_billiard() var billiard := target.get_billiard()
if camera_tweening: if event is InputEventMouseMotion and MouseControl.mouse_is_locked() and get_charge() == 0.0:
return
if event is InputEventMouseMotion and MouseControl.mouse_is_locked() and get_charge() == 0.0 :
rotate_view(event.relative*sensitivity) rotate_view(event.relative*sensitivity)
if event.is_action_released("charge") and not billiard.can_hit and charge_tween != null: if event.is_action_released("charge") and not billiard.can_hit and charge_tween != null:
release() release()
if event.is_action_pressed("charge") and billiard.can_hit and charge_tween == null: if event.is_action_pressed("charge") and billiard.can_hit and charge_tween == null:
charge(event.get_action_strength("charge")) charge(event.get_action_strength("charge"))
func _process(delta): func _process(_delta):
transform.origin = target.global_position transform.origin = target.global_position
%camera_spot.look_at(target.global_position) camera.global_position = %camera_spot.global_position
if not camera_tweening: camera.look_at(target.global_position)
camera.global_transform = %camera_spot.global_transform
else:
camera.global_position = lerp(camera.global_position, %camera_spot.global_position, 0.00000000001)
camera.global_rotation = lerp(camera.global_rotation, %camera_spot.global_rotation, 0.00000000001)
var epsilon: float = 0.0001
if (camera.global_position - %camera_spot.global_position).length() <= epsilon and (camera.global_rotation - %camera_spot.global_rotation).length() <= epsilon:
camera_tweening = false
if get_charge() >= 1.0: if get_charge() >= 1.0:
cancel_charge() cancel_charge()
@ -68,7 +46,6 @@ func release():
%ChargeReleaseSound.play() %ChargeReleaseSound.play()
var billiard := target.get_billiard() var billiard := target.get_billiard()
billiard.hit((target.global_position - %camera_spot.global_position).normalized(), get_charge()) billiard.hit((target.global_position - %camera_spot.global_position).normalized(), get_charge())
%radial_ui.set_charge(0.0) %radial_ui.set_charge(0.0)
%ChargeSound.stop() %ChargeSound.stop()
if charge_tween != null: if charge_tween != null:
@ -90,13 +67,8 @@ func rotate_view(amount: Vector2):
%rotate_helper.rotate_z(amount.y) %rotate_helper.rotate_z(amount.y)
%rotate_helper.rotation_degrees.z = clampf(%rotate_helper.rotation_degrees.z, -77, 77) %rotate_helper.rotation_degrees.z = clampf(%rotate_helper.rotation_degrees.z, -77, 77)
func set_target(node: Node3D):
func set_target(node: Node3D, should_create_tween=true):
camera_tweening = should_create_tween
var ntarget = Targetable.is_targetable(node) var ntarget = Targetable.is_targetable(node)
var billiard = ntarget.get_billiard()
billiard.can_hit = true
if ntarget == null: if ntarget == null:
push_error("Node is node targetable", node) push_error("Node is node targetable", node)
return return

View File

@ -35,6 +35,8 @@ func change_all_materials(mesh: MeshInstance3D):
layer1.render_priority = 20 layer1.render_priority = 20
layer2.render_priority = 30 layer2.render_priority = 30
layer0.no_depth_test = true layer0.no_depth_test = true
layer0.transparency = BaseMaterial3D.TRANSPARENCY_ALPHA_DEPTH_PRE_PASS layer0.transparency = BaseMaterial3D.TRANSPARENCY_ALPHA_DEPTH_PRE_PASS
layer0.grow = true layer0.grow = true
@ -45,12 +47,26 @@ func change_all_materials(mesh: MeshInstance3D):
layer2.depth_draw_mode = BaseMaterial3D.DEPTH_DRAW_ALWAYS layer2.depth_draw_mode = BaseMaterial3D.DEPTH_DRAW_ALWAYS
mesh.set_surface_override_material(i, layer0) mesh.set_surface_override_material(i, layer0)
#mesh.set_surface_override_material(i, mat)
#mat.next_pass = preload("control_target_overlay.material")
func unchange_all_materials(mesh: MeshInstance3D): func unchange_all_materials(mesh: MeshInstance3D):
for i in range(mesh.get_surface_override_material_count()): for i in range(mesh.get_surface_override_material_count()):
var mat := mesh.get_active_material(i) var mat := mesh.get_active_material(i)
var layer2: StandardMaterial3D = mat.next_pass.next_pass unchange_material(mat)
mesh.set_surface_override_material(i, layer2) while mat.next_pass != null:
layer2.transparency = BaseMaterial3D.TRANSPARENCY_DISABLED unchange_material(mat.next_pass)
layer2.depth_draw_mode = BaseMaterial3D.DEPTH_DRAW_OPAQUE_ONLY mat = mat.next_pass
mat.next_pass = null
func change_material(mat: BaseMaterial3D) -> BaseMaterial3D:
mat = mat.duplicate()
mat.render_priority = 100
mat.no_depth_test = true
return mat
func unchange_material(mat: BaseMaterial3D) -> BaseMaterial3D:
mat.render_priority = 0
mat.no_depth_test = false
return mat

View File

@ -1,4 +1,3 @@
extends Node extends Node
signal new_target(node: Billiard) signal new_target(node: Node)
signal billiard_touched_billiard(who: Billiard, touched: Billiard)

View File

@ -8,9 +8,3 @@ var can_hit = true
func hit(impulse: Vector3, power: float): func hit(impulse: Vector3, power: float):
apply_central_impulse(impulse * lerp(power_min, power_max, power)) apply_central_impulse(impulse * lerp(power_min, power_max, power))
func _on_body_shape_entered(_body_rid, body, _body_shape_index, _local_shape_index):
if body is Billiard:
ControllerEventBus.billiard_touched_billiard.emit(self, body)

View File

@ -6,13 +6,9 @@
[node name="billiard" type="RigidBody3D"] [node name="billiard" type="RigidBody3D"]
continuous_cd = true continuous_cd = true
max_contacts_reported = 1
contact_monitor = true
script = ExtResource("1_a0fke") script = ExtResource("1_a0fke")
[node name="is_targetable" parent="." instance=ExtResource("2_yrk4o")] [node name="is_targetable" parent="." instance=ExtResource("2_yrk4o")]
[node name="is_TASable" parent="." node_paths=PackedStringArray("_assignedRigidBody3D") instance=ExtResource("3_oj26f")] [node name="is_TASable" parent="." node_paths=PackedStringArray("_assignedRigidBody3D") instance=ExtResource("3_oj26f")]
_assignedRigidBody3D = NodePath("..") _assignedRigidBody3D = NodePath("..")
[connection signal="body_shape_entered" from="." to="." method="_on_body_shape_entered"]