- Home /
Endless Runner Ground Issue
So I have been working on an endless runner that does not actually move the player forward. Platforms and other objects move toward the character making it seem like he is running forward.
To make the game more challenging, I have made it so that the platforms speed up as time progresses.
This is the code for my platforms:
public Rigidbody body;
public GameObject platform;
void Update () {
if(Timer.speedUp1){
body.velocity = new Vector3(5,0,0);
Destroy(platform, 25F);
}
if (Timer.speedUp2)
{
body.velocity = new Vector3(10, 0, 0);
Destroy(platform, 18F);
}
if (Timer.speedUp3)
{
body.velocity = new Vector3(15, 0, 0);
Destroy(platform, 15F);
}
}
}
I also have a platform spawner that instantiates an array of these platforms. The delay between each instantiation is decreased when the speed goes up:
public GameObject[] prefabs;
int pObject;
public float canSpawn = 0.0F;
void Update()
{
pObject = Random.Range(0, 12);
if (Time.time > canSpawn)
{
Instantiate(prefabs[pObject], new Vector3(-134, -61.23F, 6F), Quaternion.identity);
if(Timer.speedUp1)
{
canSpawn = Time.time + 1.68F; //Speed 1
}
if (Timer.speedUp2)
{
canSpawn = Time.time + 0.833F; //Speed 2
}
if (Timer.speedUp3)
{
canSpawn = Time.time + .547F; //Speed 3
}
}
}
There is nothing really wrong with the code, it works fine. My problem is the spacing between each platform after being instantiated. This is not much of a problem when at speed 1, but it can get pretty hectic in speeds 2 and 3.
The gaps are usually like this, and can be very problematic. They will either launch my character up if he is caught in it, or clip him through the ground. I have spent days trying to fix this, but to no avail. This issue basically renders my game unplayable. Is there any way to prevent these gaps?
Any help is greatly appreciated.
First of all change it to FixedUpdate () and Time.fixedDeltaTime since that is when the Rigidbodies move and it's at regular intervals.
This will also help calculate better how much time until you spawn the next block
Time.fixedDeltaTime = 0.02; 50 steps in a second.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Check for collision while animating 0 Answers
Jump on the ground 2 Answers
i can see my objects collide but OnCollisionEnter never called c# 1 Answer