
[ad_1]
Quick query associated to Unity: if I’ve two objects (A and B) to create some tunnel, how can I make a relentless hole? I considered having A and B instantiated with a random worth to begin with; nonetheless, it is not going to be fixed hole. So I used to be questioning what different methods are (as I’m studying now, there may be Vector3.Distance technique; however implementing it makes it a bit bit extra complicated). The concept is to have your participant undergo to this hole fixed of object A and B.
Picture for instance:
However, the gaps have inconsistencies as a result of they aren’t clear. Sometimes there are actually shut collectively and the pink ball can’t even undergo (like the following picture)
This is the code instance that I’ve at this second:
utilizing System.Collections;
utilizing System.Collections.Generic;
utilizing UnityEngine;
public class SpawnManager : MonoBehaviour
{
public GameObject[] obstaclesPrefab;
non-public float startDelay = 2;
non-public float repeatRate = 2;
non-public PlayerControl playerControllerScript;
float hole = 4;
// Start is known as earlier than the primary body replace
void Start()
{
playerControllerScript = GameObject.Find("Tomato").GetComponent<PlayerControl>();
InvokeRepeating("SpawnObstacle", startDelay, repeatRate);
}
// Update is known as as soon as per body
void Update()
{
}
void SpawnObstacle()
{
int obstaclesIndex = Random.Range(0, obstaclesPrefab.Length);
float randomY = Random.Range(-1.0f, 2.0f);
float randomY2 = Random.Range(-1.0f, 2.0f);
Vector3 pipe = new Vector3(25, randomY * hole, -10);
Vector3 pipe2 = new Vector3(25, randomY2 * hole, -10);
float distance = Vector3.Distance(pipe2, pipe);
if (playerControllerScript.gameOver == false)
{
Instantiate(obstaclesPrefab[obstaclesIndex], pipe2, obstaclesPrefab[obstaclesIndex].remodel.rotation);
Instantiate(obstaclesPrefab[obstaclesIndex], pipe, obstaclesPrefab[obstaclesIndex].remodel.rotation);
}
}
}
I’m open to strategies as I’m getting began with sport growth and studying too. Thank you for time and have an ideal day!
[ad_2]