Monday, June 23, 2025

Modular Pathfinding Between Connections

I am making a puzzle for my recreation, the place it’s a must to organize pipes to transmit {an electrical} circulate from one level to the opposite. Every pipe heart incorporates a connector hub and every finish incorporates the connector. Once they contact one other, they type a connection. The issue is that I can not reliably set connections.

I need to create an branching algorithm for every hub, within the discover supply methodology, that collects each single hub that is linked to it by means of different related hubs, to seek out the one with begin worth being true (which is the unique supply of energy). I’ve tried for loops, however they should search each single department.

With pipes regularly transferring, connections need to be made and disconnected in actual time.

Modular Pathfinding Between Connections

Hub Script up to now:

public class ConnectorHub : MonoBehaviour
{
    public Connector() connectors;
    public Listing<ConnectorHub> connectedHubs = new Listing<ConnectorHub>();
    public bool stay;
    public bool begin;
    public ConnectorHub src; //The orignal stay feed.
    public UnityEvent OnLiveActice = new UnityEvent();
    public UnityEvent OnLiveDeactice = new UnityEvent();
    // Begin is known as earlier than the primary body replace
    void Begin()
    {
        if (begin) src = this;
        connectors= GetComponentsInChildren<Connector>();
    }
    non-public void Replace()
    {
        FindSource();
    }
    void FindSource()
    {

    }
    public void SetLive(bool worth) 
    {
        //stop repetition
        if(stay == worth) return;
        stay = worth;
        if (stay)
            OnLiveActice.Invoke();
        else
            OnLiveDeactice.Invoke();
    }
}

Connector Script:

(RequireComponent(typeof(Rigidbody)))
public class Connector : MonoBehaviour
{
    public ConnectorHub hub;
    public ConnectorHub related;
    non-public void Begin()
    {
        GetComponent<Rigidbody>().isKinematic = true;
        GetComponent<Rigidbody>().useGravity = false;
        hub = GetComponentInParent<ConnectorHub>();
    }
    non-public void OnTriggerEnter(Collider different)
    {
        if (hub.begin) return;
        if (different.GetComponent<Connector>())
        {
            related = different.GetComponent<Connector>().hub;
        }
    }
    non-public void OnTriggerExit(Collider different)
    {
        if (hub.begin) return;
        if (different.GetComponent<Connector>())
        {
            related = null;
        }
    }
}

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles