Python Ursina: way to disable entities far away to decrease the lag? - Stack Overflow

I wouldn't call it much of a problem, but it really affects a project I'm working on.Now, I

I wouldn't call it much of a problem, but it really affects a project I'm working on. Now, I do understand that running a Minecraft clone with 1900 blocks isn't a good idea if you want high FPS, but the problem is that it's just 3 layers of blocks on a 25x25 world, meaning I'll probably encounter FPS 5 times lower in the future. My question is: Is there any kind of property, or way to disable the entities when they're far away.

I've tried this:

for block in blocks: 
    if distance(player, block) > 10:
        block.disable()
    else:
        block.enable()

But this makes the game lag a lot as well, since it checks every block several times a second. My next idea was to run that every 60 frames, but the blocks being disabled doesn't actually seem to increase the FPS. I've tried using a mesh but I'm pretty sure that I cannot divide it back into blocks, and since this is a MC clone, that's a must have for the game. And also, there's a similar post/question where most of the answers are talking about meshes. Lastly, yes, I have in fact tried this code and I currently still have it in the program:

camera.clip_plane_far = 10

What I tried, what I expected and what actually happened:

Tried to render lots of entities at once with limited render distance, expected it to not lag a lot, it lagged a lot.

I wouldn't call it much of a problem, but it really affects a project I'm working on. Now, I do understand that running a Minecraft clone with 1900 blocks isn't a good idea if you want high FPS, but the problem is that it's just 3 layers of blocks on a 25x25 world, meaning I'll probably encounter FPS 5 times lower in the future. My question is: Is there any kind of property, or way to disable the entities when they're far away.

I've tried this:

for block in blocks: 
    if distance(player, block) > 10:
        block.disable()
    else:
        block.enable()

But this makes the game lag a lot as well, since it checks every block several times a second. My next idea was to run that every 60 frames, but the blocks being disabled doesn't actually seem to increase the FPS. I've tried using a mesh but I'm pretty sure that I cannot divide it back into blocks, and since this is a MC clone, that's a must have for the game. And also, there's a similar post/question where most of the answers are talking about meshes. Lastly, yes, I have in fact tried this code and I currently still have it in the program:

camera.clip_plane_far = 10

What I tried, what I expected and what actually happened:

Tried to render lots of entities at once with limited render distance, expected it to not lag a lot, it lagged a lot.

Share Improve this question asked Feb 23 at 9:56 LimeSpeedCrystalLimeSpeedCrystal 12 bronze badges 1
  • You can have a look at chunk system, and reducing the amount of inner faces by making cubes by quads with specified parent, checking if two overlap, removing both of them and parentbine() the resulting shape. If you need to destroy the blocks, you can check out vertices of mesh and reduce it in y direction, the reverse for adding a block. – Tanay Commented Apr 8 at 16:35
Add a comment  | 

1 Answer 1

Reset to default 0

Your game is still keeping too many entities active in memory and performing updates on them.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745158633a4614275.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信