Spawned items now bounce.

main
Martin Felis 2024-11-16 20:43:12 +01:00
parent 396d884ff0
commit ba088a1e4b
4 changed files with 28 additions and 4 deletions

View File

@ -9,7 +9,6 @@ size = Vector3(0.5, 0.483398, 0.5)
[node name="Grass" type="Node3D"] [node name="Grass" type="Node3D"]
script = ExtResource("1_sc4bm") script = ExtResource("1_sc4bm")
seed_drop_rate = null
is_chopped = false is_chopped = false
[node name="grassLarge" parent="." instance=ExtResource("2_4frmr")] [node name="grassLarge" parent="." instance=ExtResource("2_4frmr")]
@ -27,7 +26,7 @@ shape = SubResource("BoxShape3D_4etwi")
[node name="GrowTimer" type="Timer" parent="."] [node name="GrowTimer" type="Timer" parent="."]
unique_name_in_owner = true unique_name_in_owner = true
wait_time = 2.0 wait_time = 2.17
[node name="ItemSpawner" parent="." instance=ExtResource("3_cuts0")] [node name="ItemSpawner" parent="." instance=ExtResource("3_cuts0")]
unique_name_in_owner = true unique_name_in_owner = true

View File

@ -10,5 +10,7 @@ func spawn() -> void:
if randf() < spawn_chance: if randf() < spawn_chance:
var pickup_item:PickupItem = pickup_item_scene.instantiate() var pickup_item:PickupItem = pickup_item_scene.instantiate()
pickup_item.item = load("res://data/items/seeds.tres") 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) get_parent().add_child(pickup_item)
pickup_item.global_transform = global_transform pickup_item.global_transform = global_transform

View File

@ -22,6 +22,10 @@ signal item_picked_up(node_path:NodePath)
world_item_node.add_child(item.scene.instantiate()) 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(): func _ready():
if item == null: if item == null:
@ -30,6 +34,8 @@ func _ready():
var item_scene = item.scene.instantiate() var item_scene = item.scene.instantiate()
world_item_node.add_child(item_scene) 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): func _on_area_3d_body_entered(body):
@ -37,3 +43,17 @@ func _on_area_3d_body_entered(body):
body.on_item_picked_up(item) body.on_item_picked_up(item)
item_picked_up.emit(get_path()) item_picked_up.emit(get_path())
queue_free() 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

View File

@ -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"] [node name="CollisionShape3D" type="CollisionShape3D" parent="Area3D"]
shape = SubResource("CylinderShape3D_1ndog") 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 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"] [connection signal="body_entered" from="Area3D" to="." method="_on_area_3d_body_entered"]