+1 vote

I want to be able to pickup items and let the items be affected by gravity. I am currently using this setup:

Rigidbody2d
---Sprite
---CollisionShape2D
---Area2D
------CollisionShape2D

I use the Area2D to detect when the player(KinematicBody2D) touches the item. Problem is with this setup when you have more than 100 items in one spot it starts to lag since it uses 2 CollisionShape2D. How could I still detect the player with only 1 CollisionShape2D?

asked 6 days ago in Projects by jujumumu (123 points)

1 Answer

0 votes

Both Rigidbody2d and Area2D need collision shapes. Instead of keeping all 100+ items in one position, do whatever is aesthetically necessary, store the items in an array and use remove_child to hide them.

answered 6 days ago by Magso (721 points)

These are supposed to be items so the player can stack 100 in the world if they want.

Ok, you could put the Area2D on the player instead of one on each item and swap the code references around from the item script into the player script. Still, I would've thought the lag would be due to the large amount of MeshInstances and environment effects.

What do you mean by MeshInstances and environment effects I think it is due to the number of collision pairs when they are pooled together.

Sorry I forgot you're using 2D. Have you checked the profiler?

What do I do in the profiler never used it.

Click start and run the game and tick what you want to see the performance of, in your case it would be Physics2D.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.