Saturday, March 11, 2023

Procedural Buildings: Flies

I've made some new additions to 3DWorld's procedural buildings: bugs. No, not that type of bug! I'm not talking about software bugs, I'm talking about insects. Flies, in particular. I've already added walking animals (rats), animals that crawl on walls (spiders ... which technically aren't animals), and animals that slide on the floor (snakes). I'm missing something that flies. I do have butterflies flying around outdoors, but they're not inside buildings.

I initially drew flies as black spheres. This looked fine initially because they were so small, but when I added logic for them to fly around the player the simple sphere model broke down. So I started by copying and pasting the code to generate the geometry for spiders, since flies have a similar look. They're both black, have bodies that can be formed from transformed spheres, have multiple eyes, and have thin legs that can be made with cylinders and cones. The differences are minor. For example, flies have only six legs rather than eight. The biggest difference is that flies have wings, and it's the wings rather than the legs that are animated. Wing animation is a simple sine wave transition between horizontal and mostly vertical, similar to how I animated butterfly wings. Wings are small and partially transparent, though the alpha blending doesn't work very well due to a lack of proper depth sorting.

Flies will fly around randomly with smooth direction changes and will avoid colliding with walls and room objects. They follow zombies around when a target gets close to them. They'll also follow the player if a trashcan, toilet, urinal, or dead animal is picked up and stored in their inventory. (Note that the player can't actually carry a urinal.) They don't do any damage or have any other gameplay effect other than getting in the player's view, buzzing constantly, and generally being annoying. Here is what it looks like to be swarmed by flies:

Flies follow the player inside a house when the player picks up a trashcan.

I recorded a video of a swarm of flies following the player around. Aren't they annoying? I'm hoping they distract the player from watching and avoiding the zombies.

At this point I have all of the components in place for adding other insect and animal types to 3DWorld's buildings. I have support for walking on the floor, climbing walls and objects, and flying through rooms. It's fun to add new creatures!


2 comments:

  1. Neat! You even have the makings of a couple food chains! Spiders eat flies, and snakes eat rats. Now, perhaps add birds? The small ones can eat both spiders and flies, and the large ones can eat both rats and snakes. Then you just need a way to generate flies (trashcan, toilet, urinal, and dead animal is a good start) and rats (perhaps dead animals, zombies, and dumpsters? And sewer drains?) and some kind of small herbivores in the wild (caterpillars, and rabbits?), and you'll have a fully simulatable ecosystem. As a bonus, rats could also eat bird eggs. Those colossal spiders you have could probably eat small birds as well.

    ReplyDelete
    Replies
    1. Thanks. Yeah, various people have suggest I have the snakes eat the rats or something similar. Maybe I can have a snake guarding some area that will bite the player unless presented with a rat? The player can currently kill rats, carry them (alive or dead), and drop them on the floor or other objects. I've been trying to think of a way to use them for gameplay.

      I do plan to add birds, but outdoor birds rather than indoor ones. I want them flying around in the city. I've added static pigeons to the ground and on trashcans, benches, and some other city objects. The plan is to figure out how to animate them and have them fly around. It's one of the many tasks on my long list.

      Delete