- Home /
Spawn endless platforms help
I'm trying to spawn endless platforms inside jumping distance of the player, and them make them spawn at the same distance away from each other. Anyone know how that could work from this? Right now the distance between the platforms grows everytime a platform spawns. The distance should stay the same every round. Need help with making the plaform distance more stable. Any other tips would also be nice of course.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GameController : PhysicsObject
{
Vector3 platformSpawn;
private GameObject[] platforms;
public GameObject platformPrefab;
private float timeSinseLastSpawned;
public float spawnRate = 4f;
public float platformMin = -1f;
public float platformMax = 3.5f;
public float spawnXPosition = 10f;
private int currentPlatform = 0;
public int platformPool = 5;
private Vector2 platformsPossition = new Vector2(10f, 0f);
void Start()
{
platforms = new GameObject[platformPool];
for (int i = 0; i < platformPool; i++)
{
platforms[i] = (GameObject)Instantiate(platformPrefab, platformsPossition, Quaternion.identity);
}
}
void Update()
{
timeSinseLastSpawned += Time.deltaTime;
if(timeSinseLastSpawned >= spawnRate)
{
timeSinseLastSpawned = 0;
float spawnYPosition = Random.Range(platformMin, platformMax);
platforms[currentPlatform].transform.position = new Vector2(spawnXPosition, spawnYPosition);
currentPlatform++;
spawnXPosition += spawnXPosition;
if (currentPlatform >= platformPool)
{
currentPlatform = 0;
}
}
}
}
Like that, exept I want platforms for the player to jump on, ins$$anonymous$$d of purely visual elements. Also I want to have an offset between the platforms, and a certain randomness to where on the y axis it spawns. But it needs to be controlled enough to only spawn on places it can be jumped to. Will see if I can use the videoes still though, so thanks for bringing them to my attention.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Platform generation using object pooling 0 Answers
Platform Generation For Endless Runner 1 Answer
Running and Jumping problems of a 2D Endless Runner 2 Answers
Random Obstacle Placement 0 Answers