Skip to content

Commit d20686d

Browse files
committed
Add collision demo scene
1 parent 05a504e commit d20686d

File tree

2 files changed

+129
-1
lines changed

2 files changed

+129
-1
lines changed

demo/rope_examples/collisions.tscn

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
[gd_scene load_steps=11 format=3 uid="uid://cdjoxiv0y7jrp"]
2+
3+
[ext_resource type="Script" uid="uid://c8aemupwcpls1" path="res://rope_examples/scripts/animation_player.gd" id="1_26382"]
4+
[ext_resource type="Script" uid="uid://b2shq2gjd4fvt" path="res://addons/ropesim/Rope.gd" id="2_f7f8s"]
5+
[ext_resource type="Texture2D" uid="uid://criwv6nuivcxy" path="res://rope_examples/icon.svg" id="3_h0ft8"]
6+
[ext_resource type="Script" uid="uid://dfppmnngy2wx4" path="res://addons/ropesim/RopeRendererLine2D.gd" id="4_gll4t"]
7+
8+
[sub_resource type="Animation" id="Animation_6b71f"]
9+
length = 0.001
10+
tracks/0/type = "value"
11+
tracks/0/imported = false
12+
tracks/0/enabled = true
13+
tracks/0/path = NodePath("Rope:position")
14+
tracks/0/interp = 1
15+
tracks/0/loop_wrap = true
16+
tracks/0/keys = {
17+
"times": PackedFloat32Array(0),
18+
"transitions": PackedFloat32Array(1),
19+
"update": 0,
20+
"values": [Vector2(-14, 19)]
21+
}
22+
tracks/1/type = "value"
23+
tracks/1/imported = false
24+
tracks/1/enabled = true
25+
tracks/1/path = NodePath("StaticBody2D/CollisionShape2D:rotation")
26+
tracks/1/interp = 1
27+
tracks/1/loop_wrap = true
28+
tracks/1/keys = {
29+
"times": PackedFloat32Array(0),
30+
"transitions": PackedFloat32Array(1),
31+
"update": 0,
32+
"values": [0.0]
33+
}
34+
35+
[sub_resource type="Animation" id="Animation_fvc1g"]
36+
resource_name = "run"
37+
length = 16.0
38+
loop_mode = 1
39+
tracks/0/type = "value"
40+
tracks/0/imported = false
41+
tracks/0/enabled = true
42+
tracks/0/path = NodePath("Rope:position")
43+
tracks/0/interp = 2
44+
tracks/0/loop_wrap = true
45+
tracks/0/keys = {
46+
"times": PackedFloat32Array(0, 3.03333, 4.01, 4.51, 5, 5.54517, 6.54, 7.54, 8.4, 9.23333, 10.4333, 11.3333, 12.2333, 14.0667),
47+
"transitions": PackedFloat32Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1),
48+
"update": 0,
49+
"values": [Vector2(-14, 19), Vector2(766, 33), Vector2(331, 91), Vector2(375, 234), Vector2(379, 405), Vector2(276, 346), Vector2(151, 80), Vector2(48, 291), Vector2(2, 36), Vector2(134, 58), Vector2(315, 359), Vector2(430, 287), Vector2(251, 66), Vector2(676, 56)]
50+
}
51+
tracks/1/type = "value"
52+
tracks/1/imported = false
53+
tracks/1/enabled = true
54+
tracks/1/path = NodePath("StaticBody2D/CollisionShape2D:rotation")
55+
tracks/1/interp = 1
56+
tracks/1/loop_wrap = false
57+
tracks/1/keys = {
58+
"times": PackedFloat32Array(0, 3.23333, 6.1, 8.53333, 11.4, 14.1),
59+
"transitions": PackedFloat32Array(1, 1, 1, 1, 1, 1),
60+
"update": 0,
61+
"values": [0.0, 6.28319, 0.0, 6.28319, 0.0, 6.28319]
62+
}
63+
64+
[sub_resource type="AnimationLibrary" id="AnimationLibrary_d00lc"]
65+
_data = {
66+
&"RESET": SubResource("Animation_6b71f"),
67+
&"moving": SubResource("Animation_fvc1g")
68+
}
69+
70+
[sub_resource type="RectangleShape2D" id="RectangleShape2D_aatbp"]
71+
size = Vector2(64, 64)
72+
73+
[sub_resource type="CircleShape2D" id="CircleShape2D_fvc1g"]
74+
radius = 43.1741
75+
76+
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_6b71f"]
77+
radius = 25.0
78+
height = 224.0
79+
80+
[node name="collisions_demo" type="Node2D"]
81+
82+
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
83+
libraries = {
84+
&"": SubResource("AnimationLibrary_d00lc")
85+
}
86+
autoplay = "moving"
87+
script = ExtResource("1_26382")
88+
89+
[node name="Rope" type="Node2D" parent="."]
90+
texture_repeat = 2
91+
position = Vector2(-14, 19)
92+
script = ExtResource("2_f7f8s")
93+
num_segments = 30
94+
rope_length = 200.0
95+
damping = 6.095
96+
num_constraint_iterations = 22
97+
render_line = false
98+
enable_collisions = true
99+
collision_radius = 5.0
100+
resolve_collisions_while_constraining = true
101+
metadata/_edit_group_ = true
102+
103+
[node name="RopeRendererLine2D" type="Line2D" parent="Rope"]
104+
show_behind_parent = true
105+
points = PackedVector2Array(0, 0, 5.72205e-06, 8.64366, 1.14441e-05, 17.2641, 1.71661e-05, 25.8513, 2.28882e-05, 34.3962, 2.76566e-05, 42.8914, 3.43323e-05, 51.3305, 4.1008e-05, 59.7084, 4.76837e-05, 68.0211, 5.43594e-05, 76.2654, 6.19888e-05, 84.4392, 6.96182e-05, 92.5406, 7.72476e-05, 100.568, 8.4877e-05, 108.522, 9.05991e-05, 116.4, 9.91821e-05, 124.203, 0.000107765, 131.931, 0.000118256, 139.582, 0.0001297, 147.158, 0.000141144, 154.659, 0.000148773, 162.083, 0.000153542, 169.432, 0.00015831, 176.704, 0.000164032, 183.902, 0.000170708, 191.023, 0.000179291, 198.068, 0.000187874, 205.038, 0.000197411, 211.932, 0.000211716, 218.75, 0.000200272, 225.492, 0.00015831, 232.159)
106+
texture = ExtResource("3_h0ft8")
107+
texture_mode = 1
108+
script = ExtResource("4_gll4t")
109+
110+
[node name="StaticBody2D" type="StaticBody2D" parent="."]
111+
position = Vector2(69, 204)
112+
113+
[node name="CollisionShape2D" type="CollisionShape2D" parent="StaticBody2D"]
114+
position = Vector2(-18, -52)
115+
shape = SubResource("RectangleShape2D_aatbp")
116+
117+
[node name="CollisionShape2D2" type="CollisionShape2D" parent="StaticBody2D"]
118+
position = Vector2(78, 43)
119+
shape = SubResource("CircleShape2D_fvc1g")
120+
121+
[node name="CollisionShape2D3" type="CollisionShape2D" parent="StaticBody2D"]
122+
position = Vector2(203, 3)
123+
rotation = -0.719538
124+
shape = SubResource("CapsuleShape2D_6b71f")
125+
126+
[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="StaticBody2D"]
127+
position = Vector2(335, 23)
128+
polygon = PackedVector2Array(-24, -54, -16, -109, 28, -120, 58, -81, 84, -119, 116, -126, 144, -61, 219, -114, 301, -101, 306, 90, 211, 113, 186, -9, 81, 91, 33, -9)

demo/rope_examples/scripts/animation_player.gd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
extends AnimationPlayer
33

44

5-
func _ready() -> void:
5+
func _enter_tree() -> void:
66
play("moving")

0 commit comments

Comments
 (0)