- Home /
Coin Genration Algorithm in Runner Game
I'm making a runner game sequel like subway surfer. Here are the following mechanics I've done:
Platform Generation
Enemy Generation
Power up Generation
Point Generation
Out of these I have problem in generating points algorithm. I have a vision of having points like Subway Surfer game. And right now I was just able to put them randomly on the lanes. Here is my code for Random distribution in lanes.
public void PositionCoins(Vector3 position) { int maxZ = (int)position.z + 17; int minZ = (int)position.z - 59; for(int i = 0;i < coinList.Count;i++) { int randomZ = Random.Range(minZ,maxZ);
int randomLane = Random.Range(1,5);
int lane;
if(!coinList[i].activeInHierarchy)
{
if(randomLane == 1)
{
coinList[i].transform.position = new Vector3(-1.35f,1.2f,randomZ);
}
else if(randomLane == 2)
{
coinList[i].transform.position = new Vector3(0.05f,1.2f, randomZ);
}
else if(randomLane == 3)
{
coinList[i].transform.position = new Vector3(1.45f,1.2f, randomZ);
}
else if(randomLane == 4)
{
coinList[i].transform.position = new Vector3(2.85f,1.2f, randomZ);
}
coinList[i].SetActive(true);
}
}
}
Now what I want is coins like Subway Surfer randomly distributed in a group of 4-5 coins, equally spaced. Any help is appreciated.
Answer by alok-kr-029 · Mar 03, 2015 at 06:30 AM
I am not reviewing your code but I will explain what I did in my game a Year ago I made a group of prefabs of coins with onTrigger in it and then randomly instantiate those prefabs with equal spacing
which worked perfectly .
Your answer

Follow this Question
Related Questions
Which game portal websites accept Unity webplayers? 31 Answers
I finish a game and I want distribute it, what I need? 1 Answer
Game Distribution dvd 0 Answers
how do i distribute data over a network once. 0 Answers
About Transprent mode 2 Answers