Im a newCoder and im trying to make a rhythm Game.
I edit a timeline to Pop note while runtime.And i wish the ground could generate by timeline edititon too.
here i have a Terrain Class to keep the terrain information.Contains “time”&”angle”.
public int time;
public string name;
public float angle;
public Terrain(int i, string j, float k)
{
time = i;
name = j;
angle = k;
}
And then i use a Dictionary to keep the terrains in timeline.
public Dictionary<int, List<Terrain>> LineTerrainDictionary = new Dictionary<int, List<Terrain>>();
private List<Terrain> Line_TerrainRangeList(int Time, string Name, float Angle)
{
List<Terrain> notesList = new List<Terrain>();
notesList.Add(new Terrain(Time, Name, Angle));
return notesList;
}
At LineGenerator Script`s Start,I calculate the pointPosition and setPosition to generate the line with terrain.
{
point.Add(new Vector3(spawnTransform.position.x, 0, 0));
for (int count = 1; count < NoteData.instance.LineTerrainDictionary.Count; count++)
{
int _initialKey;
int _nextKey;
float _tempTime;
_initialKey = NoteData.instance.LineTerrainDictionary.ElementAt(count - 1).Key;
_nextKey = NoteData.instance.LineTerrainDictionary.ElementAt(count).Key;
_tempTime = (float)(_nextKey - _initialKey) / 1000f;
float _distance = speed * _tempTime;
float angleRed = Mathf.Deg2Rad * NoteData.instance.LineTerrainDictionary[_nextKey][0].angle;
if (NoteData.instance.LineTerrainDictionary[_nextKey][0].angle == 0)
{
point.Add(point[count - 1] + new Vector3(_distance, 0, 0));
}
else if(NoteData.instance.LineTerrainDictionary[_nextKey][0].angle > 0)
{
point.Add(point[count - 1] + new Vector3(Mathf.Abs(_distance * Mathf.Cos(angleRed)),Mathf.Abs(_distance * Mathf.Sin(angleRed)),0));
}
else if (NoteData.instance.LineTerrainDictionary[_nextKey][0].angle < 0)
{
point.Add(point[count - 1] + new Vector3(Mathf.Abs(_distance * Mathf.Cos(angleRed)), _distance * Mathf.Sin(angleRed),0));
}
}
lineRenderer.positionCount = point.Count;
for (int j = 0; j < point.Count; j++)
{
lineRenderer.SetPosition(j, point[j]);
}
}
but the result is wrong, some line pieces`s length are too short or too long.
I cant find the reason,some big Bro please help me TvT !!!
i tried to generate terrain ground piece by piece but the connection has something wrong,so i try to make terrain using LineRenderer.
if you have a better way to make it,please tell me,I ll try it.Thank you!
Bawang is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.