Friday, June 27, 2025
spot_img

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} stream 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 kind a connection. The issue is that I can not reliably set connections.

I wish to create an branching algorithm for every hub, within the discover supply methodology, that collects each single hub that is linked to it via 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 continuously shifting, connections should be made and disconnected in actual time.

Current Setup

Hub Script to date:

public class ConnectorHub : MonoBehaviour
{
    public Connector[] connectors;
    public Checklist<ConnectorHub> connectedHubs = new Checklist<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 known as earlier than the primary body replace
    void Begin()
    {
        if (begin) src = this;
        connectors= GetComponentsInChildren<Connector>();
    }
    personal 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;
    personal void Begin()
    {
        GetComponent<Rigidbody>().isKinematic = true;
        GetComponent<Rigidbody>().useGravity = false;
        hub = GetComponentInParent<ConnectorHub>();
    }
    personal void OnTriggerEnter(Collider different)
    {
        if (hub.begin) return;
        if (different.GetComponent<Connector>())
        {
            related = different.GetComponent<Connector>().hub;
        }
    }
    personal 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

- Advertisement -spot_img

Latest Articles