- Home /
2D infinite runner obstacle generation?
Hi Unity, I am developing a game that has 2 types of obstacles: One that you have to jump over and one that you have to slide under. How could i generate them randomly without them generating on top of each other (they must be far apart or else the player wont have a chance to avoid them and survive). Thanks in advance!
Answer by FirePlantGames · Nov 26, 2014 at 11:21 PM
Use this for a concept than elaborate with me and we can work towards your goal a little more;
if (!obj)
obj = Instantiate(object,Vector3(Random.Range(spawnRange.x,spawnRange.y),transform.position.y,transform.position.z + 20),transform.rotation);
else
obj = Instantiate(object,Vector3(Random.Range(spawnRange.x,spawnRange.y),transform.position.y,obj.transform.position.z + options.obstacleSpacing),transform.rotation);
Sorry that the formatting is messed up, this sight doesn't have a very good snippet system :P
Your answer
![](https://koobas.hobune.stream/wayback/20220613172516im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Random obstacles spawn in 2D side endless runner game ? 2 Answers
C# 2D InfiniteRunner run with same speed even when going up 1 Answer
I only want my character to jump when touching the ground 4 Answers
Rigidbody2d.velocity making character stop in between 1 Answer
camera follow with distance 1 Answer