AI Save/Load

Do you guys have any opinion on how to save location for animals etc. in a infinite tile terrain like minecraft, would I have to save the position for each AI char or is there another way?

Depends. If you don’t care exactly where your animals are then you could just generate new positions. Or, if the positions of the animals can be worked out (e.g. “I placed a cow at (0, 0, 0) and 200 seconds have elapsed so now the cow must be at (200, 0, 0)”) then you could just re-work-them-out on load. Otherwise, yes, you will need to save the information.

You can, of course, combine these approaches - for example, maybe it’s important to save the positions of all mobs within 100m of the player, but for mobs that are further away you don’t care and will just generate new ones.

How about syncing them over the network? I would have to send the info if the player enters the same area as the player he would have to have the same AI walking the same areas and so on.

Couldn’t you just save the last known Vector3 position then reload it from the last known position and rotation?
Never tried it, but it seems like that would work?

I’m assuming to use an RPC Buffered All would do it.

You could have the animals as procedural elements generated with the terrain that the players are on as a biome or fauna layer. Then you only need to store animals around the players.

Or what superpig said.

I was just wondering that if there is a new player entering the area, where a player already has loaded the animals with a networking script attached to it, so there is already like 3 animals in the area. How would I prevent the new player from just instantiate 3 new animals? Would I have to give the animals data which shows which Chunk they were instantiated on, and then count how many there is already from the entered chunk?

Since PlayerPrefs doesn’t have a vector component, I guess you will have to set xyz values manually.

For example,

PlayerPrefs.SetFloat("myX", animalTransform.position.x);
PlayerPrefs.SetFloat("myY", animalTransform.position.y);
PlayerPrefs.SetFloat("myZ", animalTransform.position.z);
PlayerPrefs.Save();

Then load it using PlayerPrefs.GetFloat();

Isn’t it easier to have a folder, where all the animal’s data is stored in binary formatted files?

Or don’t use PlayerPrefs. Especially for something like saving gamestate of a number of objects in your scene. PlayerPrefs is good for exactly what its name implies - player preferences.

If you are saving the state of the gameworld, you should be using a proper save/load solution.

In other words, this idea isn’t suitable to a web platform. Try a PC/Mac/Linux build instead.

How would I go about networking the animals movement? I am using aron granbergs A*. The server has to have all the vector3’s on their computer to save them to a file. But the movement is calculated client side.