[Python] Python Ursina: way to disable entities far away to decrease the lag?

Discussão em 'Python' iniciado por Stack, Fevereiro 23, 2025.

  1. Stack

    Stack Membro Participativo

    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.

    Continue reading...

Compartilhe esta Página