Skip to content

Commit cd31899

Browse files
Add moving car and object placement.
1 parent f3afa55 commit cd31899

File tree

5 files changed

+73
-9
lines changed

5 files changed

+73
-9
lines changed

addons/spawn/SpawnPoint.gd

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ class_name SpawnPoint, "res://addons/spawn/SpawnPoint.png"
22

33
extends Spatial
44

5+
signal is_depleted(who)
6+
signal item_placed(item)
7+
58
# Can tool cleanup the interface?
69
# https://docs.godotengine.org/en/stable/tutorials/misc/running_code_in_the_editor.html#doc-running-code-in-the-editor
710
# tool
@@ -13,11 +16,13 @@ export (float) var new_wave_every_seconds = 2.0
1316

1417
export (int) var capacity = 50
1518
export (int) var wave_size = 5
19+
export (NodePath) var place_products_into
1620
export (Array, PackedScene) var products
1721

1822
onready var add_to_parent = get_node("..")
1923
onready var timer:Timer = $Timer
2024

25+
onready var node_to_place_products_into:Node = get_node(place_products_into)
2126
var products_left: int = capacity
2227

2328
var spawn_point: SpawnPointClass
@@ -37,9 +42,22 @@ func _on_Timer_timeout():
3742
do_wave()
3843

3944
func do_wave():
45+
if not visible:
46+
return
47+
48+
if spawn_point.is_depleted():
49+
emit_signal("is_depleted", self)
50+
return
51+
4052
var items:Array = spawn_point.do_wave()
4153

4254
for p in items:
43-
add_to_parent.call_deferred("add_child", p)
55+
node_to_place_products_into.call_deferred("add_child", p)
56+
57+
p.translation = global_transform.origin - node_to_place_products_into.global_transform.origin
58+
59+
emit_signal("item_placed", p)
4460

45-
p.translation = translation
61+
# React on the item being placed
62+
func _on_SpawnPoint_item_placed(item):
63+
pass

addons/spawn/demos/3D/Ball.tscn

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
[gd_scene load_steps=3 format=2]
22

3-
[sub_resource type="SpatialMaterial" id=3]
3+
[sub_resource type="SpatialMaterial" id=1]
44
albedo_color = Color( 0.415686, 0.0431373, 0.0431373, 1 )
55

6-
[sub_resource type="SphereShape" id=4]
7-
radius = 0.1
6+
[sub_resource type="SphereShape" id=2]
7+
margin = 0.001
8+
radius = 0.05
89

910
[node name="Ball" type="RigidBody"]
1011
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.8557, 0 )
1112

1213
[node name="CSGSphere" type="CSGSphere" parent="."]
1314
radius = 0.1
14-
material = SubResource( 3 )
15+
material = SubResource( 1 )
1516

1617
[node name="CollisionShape" type="CollisionShape" parent="."]
17-
shape = SubResource( 4 )
18+
shape = SubResource( 2 )

addons/spawn/demos/3D/BallGreen.tscn

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[gd_scene load_steps=3 format=2]
2+
3+
[ext_resource path="res://addons/spawn/demos/3D/Ball.tscn" type="PackedScene" id=1]
4+
5+
[sub_resource type="SpatialMaterial" id=1]
6+
albedo_color = Color( 0.0862745, 0.776471, 0.0784314, 1 )
7+
8+
[node name="BallGreen" instance=ExtResource( 1 )]
9+
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0 )
10+
mass = 0.2
11+
12+
[node name="CSGSphere" parent="." index="0"]
13+
radius = 0.05
14+
material = SubResource( 1 )

addons/spawn/demos/3D/Car.gd

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
extends CSGBox
2+
3+
4+
func _process(delta):
5+
translation.x += 0.01
6+
7+
8+
func _on_SpawnPoint_item_placed(item):
9+
# Place dropped items a little randomly
10+
item.translation.x += (randf() - 0.5) / 10.0
11+
item.translation.z += (randf() - 0.5) / 10.0

addons/spawn/demos/3D/SpawnPointDemo3D.tscn

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1-
[gd_scene load_steps=6 format=2]
1+
[gd_scene load_steps=9 format=2]
22

33
[ext_resource path="res://addons/spawn/SpawnPoint.tscn" type="PackedScene" id=1]
44
[ext_resource path="res://addons/spawn/demos/3D/Ball.tscn" type="PackedScene" id=2]
5+
[ext_resource path="res://addons/spawn/demos/3D/Car.gd" type="Script" id=3]
6+
[ext_resource path="res://addons/spawn/demos/3D/BallGreen.tscn" type="PackedScene" id=4]
7+
8+
[sub_resource type="SpatialMaterial" id=4]
9+
albedo_color = Color( 0.87451, 0.0666667, 0.0666667, 1 )
510

611
[sub_resource type="QuadMesh" id=1]
712

@@ -17,9 +22,10 @@ extents = Vector3( 1, 1, 0.1 )
1722
transform = Transform( 1, 0, 0, 0, 0.947891, 0.318595, 0, -0.318595, 0.947891, 0, 1.60121, 2.20038 )
1823

1924
[node name="SpawnPoint" parent="." instance=ExtResource( 1 )]
20-
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.47483, 0 )
25+
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -0.902502, 1.47483, 0.527088 )
2126
new_wave_every_seconds = 1.0
2227
wave_size = 1
28+
place_products_into = NodePath("..")
2329
products = [ ExtResource( 2 ) ]
2430

2531
[node name="CSGTorus" type="CSGTorus" parent="SpawnPoint"]
@@ -30,6 +36,7 @@ ring_sides = 10
3036

3137
[node name="SpawnPoint2" parent="." instance=ExtResource( 1 )]
3238
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 1.65414, 0.634445, -3.17343 )
39+
place_products_into = NodePath("..")
3340
products = [ ExtResource( 2 ) ]
3441

3542
[node name="CSGTorus" type="CSGTorus" parent="SpawnPoint2"]
@@ -38,6 +45,18 @@ outer_radius = 0.4
3845
sides = 32
3946
ring_sides = 10
4047

48+
[node name="Car" type="CSGBox" parent="."]
49+
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -2.596, 2, 0 )
50+
width = 0.5
51+
height = 0.1
52+
depth = 0.5
53+
material = SubResource( 4 )
54+
script = ExtResource( 3 )
55+
56+
[node name="SpawnPoint" parent="Car" instance=ExtResource( 1 )]
57+
place_products_into = NodePath("../..")
58+
products = [ ExtResource( 4 ) ]
59+
4160
[node name="KinematicBody" type="KinematicBody" parent="."]
4261
transform = Transform( 10, 0, 0, 0, -4.37114e-07, 1, 0, -10, -4.37114e-08, 0, 0, 0 )
4362

@@ -48,3 +67,4 @@ material = SubResource( 2 )
4867

4968
[node name="CollisionShape" type="CollisionShape" parent="KinematicBody"]
5069
shape = SubResource( 3 )
70+
[connection signal="item_placed" from="Car/SpawnPoint" to="Car" method="_on_SpawnPoint_item_placed"]

0 commit comments

Comments
 (0)