I’m making an endless runner. And I already have a few obstacles. I want to make some holes in the floor. So that the player would die when he falls. But the problem is that the player doesn’t really move forward. Only the obstacles move. So the floor doesn’t move either. Because then the player gets pushed backwards. I really have no clue how to fix this. I though about checking the z position in place. Which wouldn’t allow the floor to move the player. But then the obstacles wouldn’t move the player either. I even thought about turning off gravity and placing the player slightly above the ground but then the player wouldn’t be able to fall. Is there a solution or do I need to start again but just move the player instead of the obstacles?
… First time making a game.
edit: Okay so I made a copy of the folder. Now my player moves instead of the obstacles. But a different problem has made itself known… How can you spawn objects always at a different position. Like now it keeps spawning at the same spot. But to make it endless, the obstacles need to spawn every time a little bit further away. Maybe this has to be in a different question. I really don’t know.
But this is what I have atm.
public GameObject[] Prefabs;
public GameObject Prefab1;
public GameObject Prefab2;
public GameObject Prefab3;
public GameObject Prefab4;
public GameObject Prefab5;
public GameObject Prefab6;
public GameObject Prefab7;
public GameObject Prefab8;
public GameObject Prefab9;
public GameObject Prefab10;
public float spawnMin = 2f;
public float spawnMax = 3f;
void Start ()
{
CreateObstacle ();
}
void CreateObstacle()
{
Invoke ("CreateObstacle", spawnMax);
int pickNr = UnityEngine.Random.Range(1, 6);
if (pickNr == 1)
{
Instantiate(Prefab1);
}
if (pickNr == 2)
{
Instantiate(Prefab2);
}
if (pickNr == 3)
{
Instantiate(Prefab3);
}
if (pickNr == 4)
{
Instantiate(Prefab4);
Instantiate(Prefab5);
}
if (pickNr == 5)
{
Instantiate(Prefab6);
Instantiate(Prefab7);
}
if (pickNr == 6)
{
Instantiate(Prefab8);
}
}