@@ -10,6 +10,8 @@ export(NodePath) var rope_path setget set_rope_path # Target rope path
1010export (float , 0 , 1 ) var rope_position = 1.0 # Position on the rope between 0 and 1.
1111export var smoothing : bool = false # Whether to smoothly snap to RopeHandle's position instead of instantly.
1212export var smoothing_speed : float = 0.5 # Smoothing speed
13+ ## If false, only affect the nearest vertex on the rope. Otherwise, affect both surrounding points when applicable.
14+ export var precise : bool = false
1315var _helper : RopeToolHelper
1416
1517
@@ -28,12 +30,27 @@ func _on_pre_update() -> void:
2830 emit_signal ("on_before_update" )
2931 var rope : Rope = _helper .target_rope
3032 var point_index : int = rope .get_point_index (rope_position )
31- var new_pos : Vector2
32- if smoothing :
33- new_pos = rope .get_point (point_index ).linear_interpolate (global_position , get_physics_process_delta_time () * smoothing_speed )
33+
34+ # Only use this method if this is not the last point.
35+ if precise and point_index < rope .get_num_points () - 1 :
36+ # TODO: Consider creating a corresponding function in Rope.gd for universal access, e.g. set_point_interpolated().
37+ var point_pos : Vector2 = rope .get_point_interpolate (rope_position )
38+ var diff := global_position - point_pos
39+ var pos_a : Vector2 = rope .get_point (point_index )
40+ var pos_b : Vector2 = rope .get_point (point_index + 1 )
41+ var new_pos_a : Vector2 = pos_a + diff
42+ var new_pos_b : Vector2 = pos_b + diff
43+
44+ _move_point (point_index , pos_a , new_pos_a )
45+ _move_point (point_index + 1 , pos_b , new_pos_b )
3446 else :
35- new_pos = global_position
36- rope .set_point (point_index , new_pos )
47+ _move_point (point_index , rope .get_point (point_index ), global_position )
48+
49+
50+ func _move_point (idx : int , from : Vector2 , to : Vector2 ) -> void :
51+ if smoothing :
52+ to = from .linear_interpolate (to , get_physics_process_delta_time () * smoothing_speed )
53+ _helper .target_rope .set_point (idx , to )
3754
3855
3956func set_rope_path (value : NodePath ):
0 commit comments