Tuesday, June 10, 2025
HomeGame DevelopmentModular Pathfinding Between Connections

Modular Pathfinding Between Connections


I am making a puzzle for my recreation, the place you need to prepare pipes to transmit {an electrical} circulation from one level to the opposite. Every pipe heart accommodates a connector hub and every finish accommodates the connector. Once they contact one other, they type 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 by way of different linked hubs, to search 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 steadily shifting, connections need to be made and disconnected in actual time.

Modular Pathfinding Between Connections

Hub Script to this point:

public class ConnectorHub : MonoBehaviour
{
    public Connector[] connectors;
    public Record<ConnectorHub> connectedHubs = new Record<ConnectorHub>();
    public bool reside;
    public bool begin;
    public ConnectorHub src; //The orignal reside 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>();
    }
    personal void Replace()
    {
        FindSource();
    }
    void FindSource()
    {

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

Connector Script:

[RequireComponent(typeof(Rigidbody))]
public class Connector : MonoBehaviour
{
    public ConnectorHub hub;
    public ConnectorHub linked;
    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>())
        {
            linked = different.GetComponent<Connector>().hub;
        }
    }
    personal void OnTriggerExit(Collider different)
    {
        if (hub.begin) return;
        if (different.GetComponent<Connector>())
        {
            linked = null;
        }
    }
}

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments