|Topic was automatically imported from the old Question2Answer platform.
When I mine a block in my game I want a item to appear in the world and when the player walks over the item it gets picked up and disappears. I want the items to be affected by gravity so they will fall until they hit a collisiondetection2d. A system similar to terraria’s system. How could I accomplish that?
In order for items to be affected by gravity, they need to either have custom logic implemented or be RigidBodies. Save yourself the trouble and create Rigidbodies.
Now, if I understand this correctly, you need some sort of falling crates or packages that the player can collect. You can create RigidBodies and detect collision with the player by using signals. I guess your player character has an Area2D which is capable of detecting collisions with other Area nodes and RigidBody nodes. So, here’s how to do this:
Go to your player’s Area2D node and create a new script.
Then create an
body_entered() signal (from the panel on the right, under Node tab)
func _on_Area2D_body_entered(body) function will appear in the Area node’s script
Write the following code in order to have the collectible destroy itself everytime it touches the Area2D node:
if body.name=='<object's name>':
You can also create a variable which changes whenever a collectible is picked.
Does that answer your question? If it does, please upvote this answer and mark it as best.
Perfect answer just what I was looking for.
jujumumu | 2019-08-06 17:42
A good answer but I want the items to collide with the world but not with each other how could I do that?
jujumumu | 2019-08-06 20:26