Sunday, October 16, 2022
HomeGame Developmentc# - Hole between two 3D objects in Unity

c# – Hole between two 3D objects in Unity


Fast query associated to Unity: if I’ve two objects (A and B) to create some tunnel, how can I make a continuing hole? I considered having A and B instantiated with a random worth to start out with; nevertheless, it is not going to be fixed hole. So I used to be questioning what different methods are (as I am studying now, there may be Vector3.Distance methodology; however implementing it makes it a bit of bit extra complicated). The thought is to have your participant undergo to this hole fixed of object A and B.

Image for instance:enter image description here
Nevertheless, the gaps have inconsistencies as a result of they don’t seem to be clear. Typically there are actually shut collectively and the pink ball can not even undergo (like the subsequent picture)enter image description here

That 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;
    personal float startDelay = 2;
    personal float repeatRate = 2;
    personal PlayerControl playerControllerScript;
    float hole = 4;
    // Begin is named earlier than the primary body replace
    void Begin()
    {
        playerControllerScript = GameObject.Discover("Tomato").GetComponent<PlayerControl>();
        InvokeRepeating("SpawnObstacle", startDelay, repeatRate);
    }

    // Replace is named as soon as per body
    void Replace()
    {
        
    }
    void SpawnObstacle()
    {
        int obstaclesIndex = Random.Vary(0, obstaclesPrefab.Size);
        float randomY = Random.Vary(-1.0f, 2.0f);
        float randomY2 = Random.Vary(-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].rework.rotation);
            Instantiate(obstaclesPrefab[obstaclesIndex], pipe, obstaclesPrefab[obstaclesIndex].rework.rotation);
        }
    }
}

I am open to recommendations as I am getting began with sport improvement and studying too. Thanks for time and have an important day!

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments