From 45a2c1ad871a5df82d307cb253d56c2da5e7c1da Mon Sep 17 00:00:00 2001 From: Luke Hubmayer-Werner Date: Sun, 19 Apr 2020 17:23:05 +0930 Subject: [PATCH] Friction point experiment --- Main.tscn | 11 ++++++----- rb2dladder.gd | 17 ++++++++++++++--- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/Main.tscn b/Main.tscn index ec1a7ae..f85dfe6 100644 --- a/Main.tscn +++ b/Main.tscn @@ -65,7 +65,7 @@ material = SubResource( 1 ) tile_set = ExtResource( 19 ) cell_size = Vector2( 8, 8 ) format = 1 -tile_data = PoolIntArray( 458753, 0, 0, 458754, 0, 0, 458755, 0, 0, 458756, 0, 0, 458757, 0, 0, 458758, 0, 0, 458759, 0, 0, 458760, 0, 0, 458761, 0, 0, 458762, 0, 0, 458763, 0, 0, 458764, -1610612736, 0, 524291, 0, 0, 524292, 0, 0, 524293, 0, 0, 524294, 0, 0, 524295, 0, 0, 524296, 0, 0, 524300, -1610612736, 0, 589825, 0, 0, 589836, -1610612736, 0, 655372, -1610612736, 0, 720897, 0, 0, 720908, -1610612736, 0, 786444, -1610612736, 0, 851969, 0, 0, 851980, -1610612736, 0, 917516, -1610612736, 0, 983041, 0, 0, 983052, -1610612736, 0, 1048588, -1610612736, 0, 1048601, 0, 0, 1048602, -1610612736, 0, 1114113, 0, 0, 1114124, -1610612736, 0, 1114137, -1073741824, 0, 1114138, 0, 0, 1114139, 0, 0, 1114140, 0, 0, 1114141, 0, 0, 1114142, -1610612736, 0, 1179660, -1610612736, 0, 1179673, -1073741824, 0, 1179674, -1610612734, 0, 1179675, -1610612735, 0, 1179676, 1610612736, 0, 1179677, 1610612736, 0, 1179678, -1610612736, 0, 1245185, 0, 0, 1245209, -1073741824, 0, 1245210, -1610612734, 0, 1245211, -1610612735, 0, 1245213, -1073741824, 0, 1245214, 0, 0, 1245215, 0, 0, 1245216, -1610612736, 0, 1310745, -1073741824, 0, 1310746, -1610612734, 0, 1310747, -1610612735, 0, 1310749, -1073741824, 0, 1310750, -1610612736, 0, 1310751, 1610612736, 0, 1310752, -1610612736, 0, 1376257, 0, 0, 1376281, -1073741824, 0, 1376282, -1610612734, 0, 1376283, -1610612735, 0, 1376285, -1073741824, 0, 1376286, 1610612736, 0, 1376287, -1073741824, 0, 1376288, 1610612736, 0, 1441817, -1073741824, 0, 1441818, 1610612736, 0, 1441819, 1610612736, 0, 1507329, 0, 0, 1572890, -1610612736, 0, 1572891, 1610612738, 0, 1572892, 1610612738, 0, 1638401, 0, 0, 1638425, 1, 0, 1638426, 1, 0, 1638427, 1610612739, 0, 1638428, 1610612739, 0, 1703957, -1610612736, 0, 1703961, 3, 0, 1703962, 3, 0, 1703963, 1610612739, 0, 1703964, 1610612739, 0, 1769473, 0, 0, 1769493, -1610612736, 0, 1769497, 2, 0, 1769498, 2, 0, 1769499, 1610612739, 0, 1769500, 1610612739, 0, 1835027, 0, 0, 1835028, 0, 0, 1835030, 1610612736, 0, 1835031, 1610612736, 0, 1835034, -1073741824, 0, 1835035, 1610612737, 0, 1835036, 1610612737, 0, 1900545, 0, 0, 1900565, -1073741824, 0, 1966101, -1073741824, 0, 2031617, 0, 0, 2162689, 0, 0, 2162690, 0, 0, 2162691, -1610612736, 0, 2228227, -1610612736, 0, 2293763, -1610612736, 0, 2359299, -1610612736, 0, 2424835, -1610612736, 0, 2424839, 0, 0, 2424840, -1610612736, 0, 2424841, -1610612736, 0, 2490371, -1610612736, 0, 2490372, -1073741820, 0, 2490376, 0, 0, 2490377, 0, 0, 2490378, 0, 0, 2490379, 0, 0, 2490380, 0, 0, 2490381, 0, 0, 2490382, 0, 0, 2490383, 0, 0, 2490395, 1, 0, 2490396, 1, 0, 2490397, 1, 0, 2490398, 1, 0, 2490399, 1, 0, 2490400, 1, 0, 2490401, 1, 0, 2490402, 1, 0, 2490403, 1, 0, 2555907, -1610612736, 0, 2555908, -1073741820, 0, 2555924, 0, 0, 2555925, 0, 0, 2555926, 0, 0, 2555931, 2, 0, 2555932, 2, 0, 2555933, 2, 0, 2555934, 2, 0, 2555935, 2, 0, 2555936, 2, 0, 2555937, 2, 0, 2555938, 2, 0, 2555939, 2, 0 ) +tile_data = PoolIntArray( 458753, 0, 0, 458754, 0, 0, 458755, 0, 0, 458756, 0, 0, 458757, 0, 0, 458758, 0, 0, 458759, 0, 0, 458760, 0, 0, 458761, 0, 0, 458762, 0, 0, 458763, 0, 0, 458764, -1610612736, 0, 458765, -1610612736, 0, 458766, -1610612736, 0, 524291, 0, 0, 524292, 0, 0, 524293, 0, 0, 524294, 0, 0, 524295, 0, 0, 524296, 0, 0, 524300, -1610612736, 0, 524301, -1610612736, 0, 524302, -1610612736, 0, 589825, 0, 0, 589836, -1610612736, 0, 589837, -1610612736, 0, 589838, -1610612736, 0, 655372, -1610612736, 0, 655373, -1610612736, 0, 655374, -1610612736, 0, 720897, 0, 0, 720908, -1610612736, 0, 720909, -1610612736, 0, 720910, -1610612736, 0, 786444, -1610612736, 0, 786445, -1610612736, 0, 786446, -1610612736, 0, 851969, 0, 0, 851980, -1610612736, 0, 851981, -1610612736, 0, 851982, -1610612736, 0, 917516, -1610612736, 0, 917517, -1610612736, 0, 917518, -1610612736, 0, 983041, 0, 0, 983052, -1610612736, 0, 983053, -1610612736, 0, 983054, -1610612736, 0, 1048588, -1610612736, 0, 1048589, -1610612736, 0, 1048590, -1610612736, 0, 1048601, 0, 0, 1048602, -1610612736, 0, 1114113, 0, 0, 1114124, -1610612736, 0, 1114125, -1610612736, 0, 1114126, -1610612736, 0, 1114137, -1073741824, 0, 1114138, 0, 0, 1114139, 0, 0, 1114140, 0, 0, 1114141, 0, 0, 1114142, -1610612736, 0, 1179660, -1610612736, 0, 1179661, -1610612736, 0, 1179662, -1610612736, 0, 1179673, -1073741824, 0, 1179674, -1610612734, 0, 1179675, -1610612735, 0, 1179676, 1610612736, 0, 1179677, 1610612736, 0, 1179678, -1610612736, 0, 1245185, 0, 0, 1245209, -1073741824, 0, 1245210, -1610612734, 0, 1245211, -1610612735, 0, 1245213, -1073741824, 0, 1245214, 0, 0, 1245215, 0, 0, 1245216, -1610612736, 0, 1310745, -1073741824, 0, 1310746, -1610612734, 0, 1310747, -1610612735, 0, 1310749, -1073741824, 0, 1310750, -1610612736, 0, 1310751, 1610612736, 0, 1310752, -1610612736, 0, 1376257, 0, 0, 1376281, -1073741824, 0, 1376282, -1610612734, 0, 1376283, -1610612735, 0, 1376285, -1073741824, 0, 1376286, 1610612736, 0, 1376287, -1073741824, 0, 1376288, 1610612736, 0, 1441817, -1073741824, 0, 1441818, 1610612736, 0, 1441819, 1610612736, 0, 1507329, 0, 0, 1572890, -1610612736, 0, 1572891, 1610612738, 0, 1572892, 1610612738, 0, 1638401, 0, 0, 1638425, 1, 0, 1638426, 1, 0, 1638427, 1610612739, 0, 1638428, 1610612739, 0, 1703957, -1610612736, 0, 1703961, 3, 0, 1703962, 3, 0, 1703963, 1610612739, 0, 1703964, 1610612739, 0, 1769473, 0, 0, 1769493, -1610612736, 0, 1769497, 2, 0, 1769498, 2, 0, 1769499, 1610612739, 0, 1769500, 1610612739, 0, 1835027, 0, 0, 1835028, 0, 0, 1835030, 1610612736, 0, 1835031, 1610612736, 0, 1835034, -1073741824, 0, 1835035, 1610612737, 0, 1835036, 1610612737, 0, 1900545, 0, 0, 1900565, -1073741824, 0, 1966101, -1073741824, 0, 2031617, 0, 0, 2162689, 0, 0, 2162690, 0, 0, 2162691, -1610612736, 0, 2228227, -1610612736, 0, 2293763, -1610612736, 0, 2359299, -1610612736, 0, 2424835, -1610612736, 0, 2424839, 0, 0, 2424840, -1610612736, 0, 2424841, -1610612736, 0, 2490371, -1610612736, 0, 2490372, -1073741820, 0, 2490376, 0, 0, 2490377, 0, 0, 2490378, 0, 0, 2490379, 0, 0, 2490380, 0, 0, 2490381, 0, 0, 2490382, 0, 0, 2490383, 0, 0, 2490395, 1, 0, 2490396, 1, 0, 2490397, 1, 0, 2490398, 1, 0, 2490399, 1, 0, 2490400, 1, 0, 2490401, 1, 0, 2490402, 1, 0, 2490403, 1, 0, 2555907, -1610612736, 0, 2555908, -1073741820, 0, 2555924, 0, 0, 2555925, 0, 0, 2555926, 0, 0, 2555931, 2, 0, 2555932, 2, 0, 2555933, 2, 0, 2555934, 2, 0, 2555935, 2, 0, 2555936, 2, 0, 2555937, 2, 0, 2555938, 2, 0, 2555939, 2, 0 ) __meta__ = { "_edit_lock_": true } @@ -146,13 +146,14 @@ script = ExtResource( 15 ) cx = 24 [node name="SprLadder5" type="RigidBody2D" parent="TileMap"] -position = Vector2( 148, 84 ) +position = Vector2( 44, 64 ) input_pickable = true mass = 10.0 +can_sleep = false script = ExtResource( 22 ) [node name="CollisionShape2D" type="CollisionPolygon2D" parent="TileMap/SprLadder5"] -polygon = PoolVector2Array( -24, -8, -24, 8, 24, 8, 24, -8 ) +polygon = PoolVector2Array( -24, -7, -24, 7, 24, 7, 24, -7 ) __meta__ = { "_edit_lock_": true } @@ -165,13 +166,13 @@ __meta__ = { } [node name="SprLadder6" type="RigidBody2D" parent="TileMap"] -position = Vector2( 44, 64 ) +position = Vector2( 220, 56 ) input_pickable = true mass = 10.0 script = ExtResource( 22 ) [node name="CollisionShape2D" type="CollisionPolygon2D" parent="TileMap/SprLadder6"] -polygon = PoolVector2Array( -24, -8, -24, 8, 24, 8, 24, -8 ) +polygon = PoolVector2Array( -24, -7, -24, 7, 24, 7, 24, -7 ) __meta__ = { "_edit_lock_": true } diff --git a/rb2dladder.gd b/rb2dladder.gd index 7507ec7..d34eb79 100644 --- a/rb2dladder.gd +++ b/rb2dladder.gd @@ -17,7 +17,7 @@ var total_weight = 7 func _ready(): - friction = 1 +# friction = 1 linear_damp = 2 angular_damp = 100 @@ -43,20 +43,31 @@ func get_belt_rect(vec): #func _process(delta): # var belt_speed = delta * 8 func _physics_process(delta): - var belt_speed = 8 * 24 + var belt_speed = 8 * 64 var direction = Vector2(0, 0) set_applied_force(Vector2(0,0)) set_applied_torque(0) + angular_velocity = 0 + var friction_points = [] for i in len(foot_vectors): var vec = beltmap.world_to_map(position + foot_vectors[i].rotated(rotation)) if beltmap.get_cell(vec.x, vec.y) >= 0: add_force(vec - position, belt_speed*dir_vectors[get_belt_direction(vec.x, vec.y)]/total_weight) #direction += dir_vectors[get_belt_direction(vec.x, vec.y)] * foot_weights[i] + else: + friction_points.append(vec - position) # position += direction/total_weight * belt_speed if held: var ggv = to_global(grabbed_vector) var dv = get_global_mouse_position() - ggv - add_force(grabbed_vector, dv * dv.abs() *friction*linear_damp) + add_force(grabbed_vector, dv * dv.length()*linear_damp) + + var f = get_applied_force() + linear_velocity*mass + var fn = f.normalized() + var fmag = f.length() + var f_max = 200 + for p in friction_points: + add_force(p, -fn * min(f_max, fmag/total_weight)) #func _input_event(_viewport, event, _shape_idx):