diff --git a/objects/grass.tscn b/objects/grass.tscn index eb6ded2..ffaf5d2 100644 --- a/objects/grass.tscn +++ b/objects/grass.tscn @@ -9,7 +9,6 @@ size = Vector3(0.5, 0.483398, 0.5) [node name="Grass" type="Node3D"] script = ExtResource("1_sc4bm") -seed_drop_rate = null is_chopped = false [node name="grassLarge" parent="." instance=ExtResource("2_4frmr")] @@ -27,7 +26,7 @@ shape = SubResource("BoxShape3D_4etwi") [node name="GrowTimer" type="Timer" parent="."] unique_name_in_owner = true -wait_time = 2.0 +wait_time = 2.17 [node name="ItemSpawner" parent="." instance=ExtResource("3_cuts0")] unique_name_in_owner = true diff --git a/objects/item_spawner.gd b/objects/item_spawner.gd index 3dbd060..d1d79c1 100644 --- a/objects/item_spawner.gd +++ b/objects/item_spawner.gd @@ -10,5 +10,7 @@ func spawn() -> void: if randf() < spawn_chance: var pickup_item:PickupItem = pickup_item_scene.instantiate() pickup_item.item = load("res://data/items/seeds.tres") + pickup_item.world_item_initial_y_position = 0.5 + pickup_item.world_item_initial_y_velocity = 3.0 get_parent().add_child(pickup_item) pickup_item.global_transform = global_transform diff --git a/objects/pickup_item.gd b/objects/pickup_item.gd index 64ccd75..01edd0c 100644 --- a/objects/pickup_item.gd +++ b/objects/pickup_item.gd @@ -22,6 +22,10 @@ signal item_picked_up(node_path:NodePath) world_item_node.add_child(item.scene.instantiate()) +var gravity = ProjectSettings.get_setting("physics/3d/default_gravity") +var world_item_initial_y_position: float = 0 +var world_item_initial_y_velocity: float = 0 +var world_item_y_velocity: float = 0. func _ready(): if item == null: @@ -30,6 +34,8 @@ func _ready(): var item_scene = item.scene.instantiate() world_item_node.add_child(item_scene) + world_item_node.position.y = world_item_initial_y_position + world_item_y_velocity = world_item_initial_y_velocity func _on_area_3d_body_entered(body): @@ -37,3 +43,17 @@ func _on_area_3d_body_entered(body): body.on_item_picked_up(item) item_picked_up.emit(get_path()) queue_free() + +func _physics_process(delta: float) -> void: + if world_item_node.position.y > 0: + world_item_y_velocity -= gravity * delta + + world_item_node.position.y += world_item_y_velocity * delta + if world_item_node.position.y < 0: + world_item_node.position.y = 0 + + if world_item_y_velocity < -1: + world_item_node.position.y = 0.01 + world_item_y_velocity *= -0.4 + else: + world_item_y_velocity = 0 diff --git a/objects/pickup_item.tscn b/objects/pickup_item.tscn index 36987b8..247b069 100644 --- a/objects/pickup_item.tscn +++ b/objects/pickup_item.tscn @@ -15,8 +15,11 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.0502824, 0) [node name="CollisionShape3D" type="CollisionShape3D" parent="Area3D"] shape = SubResource("CylinderShape3D_1ndog") -[node name="WorldItemNode" type="Node3D" parent="."] +[node name="WorldItemOffset" type="Node3D" parent="."] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.06, 0) + +[node name="WorldItemNode" type="Node3D" parent="WorldItemOffset"] unique_name_in_owner = true -transform = Transform3D(-0.319655, 0.240352, 0.00715891, 0, 0.0119088, -0.399823, -0.240459, -0.319514, -0.00951674, -0.035, 0.06, 0.021) +transform = Transform3D(-0.257115, -0.306418, 0, -1.33939e-08, 1.12389e-08, -0.4, 0.306418, -0.257115, -1.74846e-08, 0, 0, 0) [connection signal="body_entered" from="Area3D" to="." method="_on_area_3d_body_entered"]