Category Archives: Weekly Update

List weekly updates.

Big Game Project – Tale

Greetings, it is time for blog posts again. This time it is for big game project. This course is about making a game in about 8 weeks, and then showing the game at the GGC conference. The game we are making is named Tale, and is developed in Unity. 

This is the third week into big game project, thought the blogging starts now. Therefore I will describe the most important discoveries, solutions and problems related to code I have encountered during these three weeks.

The main things I have coded during the first weeks are:

  • A state-machine for AI
  • Simple AI behavior
  • Rope
  • Rope swinging
  • Rope(physics based)
  • Rope(climbing, descending)

State-machine:

For the state machine I tried following this tutorial. I followed this tutorial since it seemed to keep the code rather clean even if the AI would be expanded with more functionality and logic later.

The tutorial uses something called interface. An interface is like making a virtual void class in C++ except that this is in Unity(C#). This means that a class that inherits the interface class needs to have the methods the interface class has. Therefore you can safely assume that all classes that inherits the interface class has the same methods.

statemachine

This enables me to make a class that holds a currentState, of the interface class type. And can change the currentState, to any other class that inherits the interface. In my case these states are(for now) alertState, detectedState, patrolState, retreatState and attackState.

So the class that holds currentState can call currentState.Update() in its own UpdateStates() function. This means that if i change currentState, the update function that will be called is the one that i changed currentState into.

statesupdate

For a more refined explanation check the tutorial.

Simple AI:

With the State machine that I made above I managed to create an enemy that patrols, chases, retreats, reloads, fire towards the player and has an attack cool-down. Though making a state for reloading, firing and attack cool-down was redundant since it will be handled by animations later.

FOV(field of view):

The enemy searches for the player with a sphere trigger. Once the player enters this trigger it checks the angle between the player and the enemy and compares it to a desired FOV.

If the player is inside of the FOV, the enemy fires a raycast to see if no obstacle is in the way of the enemy for seeing the player. If nothing is in the way, it means that the enemy sees the player.

rayCast

Rope and more ropes:

The main focus for me these couple of weeks and coming weeks has been concerning making ropes. This is because we want a high variety of functionality of the rope. As a player you will be able to the following with a rope. Interact with enemies, swing, increase/decrease tether length, climb/descend, pull objects and probably something more.

Physics based rope:

The first attempt at making a rope I used Unitys Character Joints. These enabled me to connect multiple colliders and bodies into a long rope and render a line between them. Visually this works fine but mechanically it breaks.

Why it did not work:

When I tried to interact with the rope by adding force to a joint, or when the rope fell. It in the most cases started to freak out(literary).  I assume the thing that happened was that when one joint was too far away from another they tried to snap, but when the snap happened the joint on he other side also tried to snap causing a ricochet of movement. This made so that the thing that was supposed to be a rope suddenly was a massive hurricane of lines. (Apparently Unity 5 has problems with physics calculations, and many forums suggests Unity 4.6X for physics games in Unity). Thought I did not try to downgrade from Unity 5.X.

Non physics based:

The solution so far is making it non-physics based. The biggest problem with the physics rope was force and high velocities therefore I wanted to make the swinging first with the non-physics rope. A great help on the way was this pseudo-code and explanation.

In short the way it works is that the object that is tether is restricted by a certain length. If the object would go outside of the radius it snaps back into range. At the start of each frame i save the objects position and in the end of the frame i save the position it snapped back to. Then by subtracting the two at the start of the frame enables me to set which velocity the object should have so that it follows around an object it is tether to according to the length of the rope.RopeSwing

(this code is under construction, that is why it is such a mess!)

For testing purposes I tried to implement this in 2D in a personal project before 3D.

Since the 2D code worked just fine, I translated it into 3D.

This is the result of the swing so far.

The climbing and descending I got working for the physics based rope, thought since I went for the non-physics I will probably rewrite it.

This was the functionality for the rope climbing on the physics rope from the first two-three days. Looks more like an rail-cart, since the rope is on the ground.

This was this weeks post, the next one will probably be shorter. Take care.

 

Game Programming I Week three.

This week of programming has been a bit more slow paced then the two previous ones. Hence we have been going through classes the whole week. The only new thing this week was class heritage, that a class can contain an other class by, heritage. This is declared by


class Animal

{

private:

int size;

public:

int GetSize(size)

{

return size;

}

};

class Fish: Public Animal   //Better to set Animal as protected

{

};

This means that the things inside class fish now contains class animal.

Second week of programming, Introduction to SDL.

So the second week of C++ programming has gone by, this has been a lot more difficult with a lot more things to learn. Including dynamic memory and pointers. We have also made a pong game using the SDL library, or well we did not do it from scratch. We followed our teachers instructions.

Here is some examples of what we have learned, that i did not know before.

& is a pointer for a specific variables memory address.

* points at the memory address and reaches the variable through it.

-> is some kind of struct or class call within SDL. ( Structs were a part of C and not C++)

a struct is a kind of class with multiple variables or functions within (a structure containing many things).

Within SDL we have also learned: Simple collision checking, the code below checks collision with ball objects and paddles.


bool check_collision(Paddle*paddle, Ball*gameBall)
{
if (paddle->x + 20.0f < gameBall->x || paddle->x>gameBall->x+ 20.0f)
return false;
if (paddle->y + 100.0f < gameBall->y || paddle->y > gameBall->y + 20.0f)
return false;
return true;

}

user input with keyboard, drawing a screen,

making structs, below are two important structs.


struct Ball //struct for ball
{
float dirx, diry;                          //The speed of which the ball moves in x and y directions
float x, y;                                  //the position of the ball
};
struct Paddle //struct for the paddles
{
float paddleSpeed = 700.0f;   //the speed of which you can move the paddles up and down
bool input[2];                          //used for the controlling of the paddles, 0 =upward, and 1 = down;
float x, y;                                //The position of the paddles
};

confirmation on how pointers work. How we make the game timebased intead of framebased, so the game runs in the same speed on all computers. And lastly a way to pause or start the game.

I have a feeling the next week will be even more intense.

The first week of GameProgramming!

So the first week of gameprogramming has gone by. Since i have studied a bit of programming in C# before i have not learned all the much from the courses. Thought it has been a great reminder on how programming works, and to adapt the previous knowledge of C# to C++. The most fundamental thing i have learned this week is that there are several ways to code the same thing, and it ts hard to differentiate which is the better way to code.

The most fundamental exercise that we have done this week was to create a guessing game. exercise 26this is the code i made for it, it works flawlessly, the program randomizes a number from 1-100 and you are supposed to guess the number 1-100

The more interesting thing is the program i am currently working on. I am trying to make a text based adventure game. With private variables only several classes and methods. Since i know that this is what I have to practice. My program is currently at 283 lines. And here is the current source code, hopefully it will be completed in the weekend  so that i can start practice using the SDL library.

Week 2, MDA-framework.

So week number two has passed. This week we were thought of the MDA framework. MDA stands for Mechanics-Dynamics-Aesthetics.

Mechanics is in short terms how a game function and what the played can do within the game.

Dynamics is how the game is played by the player.

Aesthetics is how the player will or should feel when playing the game.

Also during this week we made a sissyfight revamp, which we call Master Ai.

It is pretty much a quiz game, which Adam(our teacher) did not even send us on a walk of shame after we presented it.