Skip to main content
GameDev.net gamedev.net

PRO Tired of ads? Read GameDev.net ad-free and help keep the community independent with GameDev Pro — $3/month.

Starting out: First pieces of life in the world

Starting out: First pieces of life in the world

RobbyT15
RobbyT15 · · 4 min read
2,113 0

I have an admission to make, I had already made some progress prior to creating this blog, it wasn't too substantial though and what I've done so far definitely requires some cleanup, modification, and improvements.

So what have I done?

Since I'm building my world first, I figured I would start with something that will exist in my world, animals. Since there are many types of animals that will exist, I decided that an abstract class or an interface would be needed to declare the common functionality that each animal would share, Walking, Running, Eating, etc., along with common properties, walk speed, run speed, etc. Once I did this, I made the specific animal class. In my case, I just made a cow, and inherited from the Animal class. Within the animal class, each animal will have a Wander function, which basically tells the animal to wander around the world, stop periodically for a random amount of time, then wander some more. This is a very simple function right now, but it will become much more complex later on. All it does is checks if the animal has reached a random point, sets a new random point, and then moves the animal to the new position once it's done waiting, it also rotates the animal towards the new random point to give the animal the appearance that it's turning while walking.

Impediments and Issues

  1. There was a very small issue I had with the cow class. Originally I had the random point set up to change within the parent Animal class, but I quickly realized that this would cause each animal to move towards the same point , then move off into random directions..
  2. One issue I've noticed I'm having is that occasionally, if the animal reaches the edge of the terrain, it'll 'skirt' the edge, meaning that part of it will hang off.
  3. On startup, the start wait time is always what I specify it to be in the editor, I need it to change to be a random value. However, When I set it to a random value in the start method, it triggers some conflicting animations and functionality when moving to the first random point.

Fixes

  1. I moved the random point within the individual cow class which allows the cow to set its own starting direction, rather than using a generic one.
  2. This issue is nothing more than correcting the bounds in which the animal can move. Changing the minimum values from 0 to 1 fixes it.
  3. It's likely nothing more than moving the function call to the right place in the code, or creating the random value in the wrong place. This will need to be investigated.

What's upcoming

Naturally, for functionality like allowing animals to wander around, I would give the responsibility to a manager, rather than the instance itself, so I'll be building an animal manager and attaching it to the world, to handle an animal's behavior. I'll also be adding more animals to the scene to make sure that the functionality works on each animal, rather than one, and giving them behaviors for when they run into each other. Finally, I'm going to form my terrain, which will show that the animals can move over hills, walk around trees, etc.

Wait, what's that?

If you're looking at my code for the animal class, you may notice that there's some properties and a function that are commented out and some hidden points in my scene. My reasoning behind this is, eventually, I would like to give regions to each animal type. In the real world, certain animals are native to certain areas. You're not going to see a herd of cattle wandering around the desert unless they're severely lost, they're going to be closer to vegetation and a water source. So this functionality will allow for that. What would be fun, is to eventually give the animals the ability to get lost, which would then trigger the functionality to wander the entire world.

Asset Credits

As I mentioned, I'm using models, animations, audio, etc that others have created as I have no ability in these fields.

Animal pack deluxe made by JANPEC

Zombie made by PXLTIGER

Fantasy Monster - Skeleton made by TEAMJOKER


IAnimal.cs

Cow.cs

Animal.cs


Unity 2018.2.13f1 Personal (64bit) - SampleScene.unity - New Unity Project - PC, Mac & Linux Standalone_ _DX11_ 10_26_2018 10_34_19 AM.mp4

Discussion

Loading comments...