Here, I've collected the useful mathematics calculation to be used in everyday game development. Keep me posted if you have other useful daily mathematics calculate useful in game.
Calculating percentage from current and maximum value
float percent =(current / maximum) * 100.0fCalculating value from the current and percentage
float value = (current * percentage) / 100.0f
Calculating Row And Columns in 2D array
/// Get the row number of the grid cell in a given index
public int GetRowFromIndex(int index, int numRows)
{
int row = Mathf.FloorToInt((float)index / (float)numColumns);
return row;
}
/// Get the column number of the grid cell in a given index
public int GetColumnFromIndex(int index, int numColumns)
{
int col = index % numColumns;
return col;
}
/// Get the index from the given row and column
public int GetIndexFromRowCol(int curRow, int curCol, int numRows, int numColumns)
{
int index = (curRow * numColumns) + curCol;
return index;
}
Comments
Post a Comment