SGD300 - week 9 Devlog


Introduction

This week I begun looking into how to create formations using Unity. The goal of this week is too create an overarching Formation script that will set the base behaviour of all formations. Using this Formation script as a parent to the actual formation will allow limit the amount of reused code because everything that is common for formations will be in the parent script.

Goals

1. Create a Formations Script that will be added to the prefab Player Controller Gameobject 

2. Add the types of formation as enum's into the formation script and add their base behaviour such as position and number of members

3.  Create Dummy button that can be used to set the formation type

Personnel

Primary - Nathaniel Hughes

Technologies, Tools, and Resources used

Provide resource information for team members who wish to learn additional information from this log.

* [Formation ideas](http://www.jeremiahwarm.com/coordinated-movement.php)

*[Array Scripting API](https://docs.unity3d.com/ScriptReference/Array.html)

*[Centre of Mass example](https://forum.unity.com/threads/finding-the-center-of-mass-of-a-collection-of-rigidbodies.87578/)

Tasks Undertaken

1. Research Formation Creation in Unity

2. Create a Formation Script

3. Add the formation to the script and create the basic behaviour of the Formation.

4. Create UI Buttons that a seperate script of Individual Formation will be added

5. Create the Individual Formation Scripts.

What we found out

I first worked on creating the Super class of Formations that will be added to the game. There are currently four formations square, circle, wedge and wall, these are stored in an Enum. In the Formation Script there are currently three methods, one to assign units to the formation, two is to set the position of the units in the formation and lastly is to calculate the center of mass of the formation to have the units always stay the same distance away from the leader.

The first method is called AssignUnit(), the method is a simple one line code that will be executed when the button to press to assign the units in the game to an array. The second method is called AssignPosition(). This code check to see if there is a currently scelected player, it loops through the array to find the transform of the arrayed gameobjects. Using the transforms position of the gameobjects and the current selected player we want to arrange their positions in formtion. The last method is to set the center point of the formation called CenterofMass(). This method for our purpose is the currently selected player.

The next thing I created was a Square Formation Script and a Circle Fomation Script that used the Formations Script as a superclass. These tow scripts were attached to two buttons I had created in the UI. 

Solution Justification

I was assigned to try and cretae the formation used in Dungeon Siege as it was a useful feature for the multiple characters in the game. The formations would give the characters uniform movement with the currently selected player as the lead. I chose to use a super class called Formations because it would remove a lot of repeat functionality that would be almost exactly the same from all the various Formations Scripts I will have to create.

Get SGD300

Leave a comment

Log in with itch.io to leave a comment.