Friday, April 12, 2019

Status so far

This project actually started around November of 2018, but after spending 4-5 months on it I decided it might be fun to write a blog so I can better document my progress, and share any insights I've gained during programming.

Here is what it looks like so far:

Currently, it has:

- Lighting:

I haven't implemented "smooth lighting" yet, but otherwise I'm pretty happy with this.

I have a "heightmap" thing that keeps track of the highest solid block at each x,z coordinate, and gives that block sunlight. This sunlight will spread out: if not touching the sun, a block's sunlight = (max of neighbor's sunlight values) - 1, clamped to have a minimum value of 0 and a maximum value of 15.

There is also a "block lighting" value that trickles in a similar way: If it is not producing light, a block's blocklight = (max of neighbor's blocklight values) - 1, clamped to have a minimum value of 0 and a maximum value of 15.

The shader has both these values, and also has a value for how "sunny" it is (from 0 to 1) that is multiplies to sunlight. In pseudocode

sunLevel = (value from 0 to 1, 0.1 at night, 1 at noon, can smoothly change at sunset)
sunLight = (value from 0 to 15)
blockLight = (value from 0 to 15)

actualLight = max(sunLevel*sunLight, blockLight)

this lets me not have to run lighting updates when it gets dark at night. I also used "tinting" so in dim lighting things get a blue shade similar to how this happens irl, due to the biology of our eyes. There isn't actually a daylight cycle yet, but there is a global "sunLevel" variable that I can change to make it look like night.

- Raycasting: I wrote code that raycasts to find when your mouse hits a block. It also raycasts to let you move around, so even if you are falling at a very fast speed you won't fall through blocks.

- Hold down shift so not fall off edges (like sneaking in minecraft)

- Block Entities and player inventories. There can be stacks of items, and items can have durability and break

- Crafting and custom recipes

- Fairly basic generation: I have caves using a perlin worms algorithm and basic hills just using perlin noise, but this could be vastly improved and is probably going to be my main next focus. I'm still tweaking with what makes a nice API here.

- Rendering: I have 16x16x16 chunks (this size might change). My world is infinite horizontally and vertically, so you can dig down as much as you want and never hit bedrock. Today I moved the rendering code to a seperate thread which makes everything feel much smoother. I don't show block faces that aren't exposed to air.

I also have a system for custom "block models" where using a format very similar to minecraft's format. This allows me to make things like this (ignore the gross textures this is just an example)

My physics engine/raycasting will actually look at the small models themselves (by raycasting to each triangle) and not just treat them as a entire block, so you get nice behavior like only breaking a torch if you click on it, and being able to breat the block below it.

- Saving: Words can be named, saved, and loaded (but the format is pretty gross right now and takes 10 seconds or so to save and load a world - I plan on improving this in the future)

I'm desigining everything to be very modular and nice to use (in terms of coding), so adding new recipes and blocks with custom behaviors is very easy to do.

- Pathfinding: I'm really happy with my current pathfinding system, it can pathfind very quickly around hundreds of blocks efficiently, but I think it'll require a seperate blog post to explain in full. There is still some things I want to do with this to enable mobs to strategically build and such as part of their pathing. I really like games like dwarf fortress and rimworld, and I'd like to have much more complex NPC AI. For those of you that follow Tango Tek's Villager Mod series, that is more along the lines of kind of gameplay that I am going for: You are a player yourself, but you interact with NPCs quite a bit to do things in the world. Except, I also want the NPC so be builing things as well with you. I want them to feel like someone you are playing with.

- Multiplayer: I don't have this yet, but this is very important to me and is a big todo in the near future.

1 comment:

  1. With so many rogue casino websites popping up on the web, it can be be} troublesome for players to choose on} an excellent on-line casino. That is why we suggest only casinos may be} respected and secure. Beyond this, Bizzo Casino also provides a 카지노사이트 mobile casino model for players preferring to play on the go.


Rendering Lots of Blocks Efficiently in Unity

The last few weeks I've spent trying to see how many blocks I can render, while keeping everything at a nice frame rate (30-60fps) with ...