Generating Random Obstacles | MAKING AN INFINITE RUNNER game like CANABALT #5 | Unity Tutorial

preview_player
Показать описание
Adding a bit of difficulty by spawning obstacles on top of the procedurally generated platforms, and of course, running into them.

Support/Follow

I also like
btc - bc1qv6ktxh9kcf6juxjxhqmyjrg6ptv48ptlqu679x
eth - 0x6b7708Ec9b120c1CA2239c9452060086f83AD9E8
doge - DKu8DjKL78THAHBz2eh3U9EGQD7QSNnWgM

Disclaimer: This video assumes you have some beginner knowledge of the Unity IDE. I am using Unity 2021, Visual Studio 2019, and Windows 10 Professional.

#gamedev #indiegamedev #gamedevelopment #unity3d #unity3d
Рекомендации по теме
Комментарии
Автор

Wow man, I didn't know you had your own channel separate to Super Game Bros. Subbed and great Tutorial

tauheedgamedev
Автор

you saved my homework man, great series

riuzakyrodriguez
Автор

Think. Code. Drink. What a great order man! I've been wanting to make an infinite runner for a while now...

DevNoob
Автор

I love your tutorials. but i have a little problem to the height of buildings... they height is so similar and this makes the game very easy. ( i don't create obsacles yet)
Here's my code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Ground : MonoBehaviour
{
Player player;

public float groundHeight;
public float groundRight;
public float screenRight;
BoxCollider2D collider;

bool didGenerateGround = false;


private void Awake()
{
player =
collider =
groundHeight = transform.position.y + (collider.size.y / 2);
screenRight = Camera.main. transform.position.x * 2;
}


void Start()
{

}

// Update is called once per frame
void Update()
{

}

private void FixedUpdate()
{
Vector2 pos = transform.position;
pos.x -= player.velocity.x * Time.fixedDeltaTime;



groundRight = transform.position.x + (collider.size.x / 2);

if (groundRight < -22f)
{
Destroy(gameObject);
return;
}

if (!didGenerateGround)
{
if(groundRight < screenRight)
{
didGenerateGround = true;
generateGround();
}
}

transform.position = pos;
}

void generateGround()
{
GameObject go = Instantiate(gameObject);
BoxCollider2D goCollider =
Vector2 pos;

float h1 = player.jumpVelocity * player.maxHoldJumpTime;
float t = player.jumpVelocity / -player.gravity;
float h2 = player.jumpVelocity * t + (0.2f * (player.gravity * (t * t)));
float maxJumpHeight = h1 + h2;
float maxY = maxJumpHeight * 0.7f;
maxY += groundHeight;
float minY = 9;
float actualY = Random.Range(minY, maxY);

pos.y = actualY - goCollider.size.y / 2;
if (pos.y > 7)
pos.y = 7;

float t1 = t + player.maxHoldJumpTime;
float t2 = Mathf.Sqrt((2.0f * (maxY - actualY))) / -player.gravity;
float totalTime = t1 + t2;
float maxX = totalTime * player.velocity.x;
maxX *= 0.7f;
maxX += groundRight;
float minX = screenRight + 5;
float actualX = Random.Range(minX, maxX);

pos.x = actualX + goCollider.size.x / 2;
go.transform.position = pos;

Ground goGround = go.GetComponent<Ground>();
goGround.groundHeight = go.transform.position.y + (goCollider.size.y / 2);
}
}
p.s my canvas is a little smaller than yours and in another position.

francescobortolamei
Автор

I got this bug where I am colliding with the obstacles but some obstacles does not disappear or slowdown my character. I do not know what is causing this bug I triple checked my code I coded it right. If anyone can help it would be great!

blurr
Автор

I'm having an issue where the obstacles are generating at heights generated by the previous platform, causing them to generate either in the platform or above it. any suggestions?

justVisfine
Автор

someone pls help! When it comes to the boxes sometimes my player just runs right through them. I have no idea what causes it and it seems to just happen randomly. Does anyone at least know what I can check or look out for to fix this. thx

rd_dimensional
Автор

My code was identical to yours, but way too many boxes where spawned and some were floating. How could i fix this? Thanks.

iloveabg
Автор

Small bug there, when you land on obstacle player falls down (never made contact with ground I guess)

TheSzymonc
Автор

Don't be stingy ! Give us the script in description link.or else I have no reason to subscribe to your channel. There are 1000s of game dev teachers in youtube

arabiannights