Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by archelyte_vz · Apr 17, 2018 at 11:37 PM · c#scripting problemunity 2ddirectional

Replicating MC Redstone Wiring

I'm trying to design a wiring system that allows players to connect power sources to switches via wires. Think redstone in Minecraft. When a wire is placed, if it is not initially connected to the power source, it has no power (behaving as expected). The PROBLEM occurs when the wire is connected to power, detecting that it is powered, and then disconnects from power. After it has touched the power source, it then becomes it's own source if disconnected, and never de-powers.

This is what SHOULD be happening alt text

Here's what is ACTUALLY alt texthappening.

And here is my code:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class Wire_Moveable : MonoBehaviour {
 
     public static Wire_Moveable control;
 
 public bool IsBlue;
     public bool IsRed;
     public bool powered;
 
 void Start () {
         IsBlue = false;
         IsRed = false;
     }
 
 void Update () {
 if (Input.GetMouseButtonUp (0)) {
             following = false;
             this.gameObject.GetComponent<Wire_Moveable>().SnapWire ();
         }
 }
 
 void OnTriggerStay2D (Collider2D trigger) {
         if (trigger.tag == "wire") {
             if (trigger.gameObject.GetComponent<Wire_Moveable>().powered) {
                 powered = true;
             }
 
             if (trigger.gameObject.GetComponent<Wire_Moveable> ().IsBlue) {
                 IsBlue = true;
                 IsRed = false;
             } else if (trigger.gameObject.GetComponent<Wire_Moveable> ().IsRed){
                 IsBlue = false;
                 IsRed = true;
             }
         }
     }
 
 void OnTriggerExit2D (Collider2D trigger) {
         if (trigger.tag == "startnode_blue") {
             IsBlue = false;
             powered = false;
         }
 
         if (trigger.tag == "wire") {
             if (trigger.gameObject.GetComponent<wire_Moveable>().powered) {
                 powered = false;
             }
         }
     }
 
 void SnapWire () {
         if (this.gameObject.name == "Wire_Basic" || this.gameObject.name == "Wire_Basic(Clone)") {
             StartCoroutine ("ActivatePower", 0);
         }
     }
 
 IEnumerator ActivatePower () {
         yield return new WaitForSeconds (0.1f);
         if (powered) {
             PowerBeam.SetActive (true);
         } else if (!powered) {
             PowerBeam.SetActive (false);
         }
     }


power-problem-01.png (35.7 kB)
power-problem-02.png (38.1 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by TreyH · Apr 19, 2018 at 07:00 PM

As a simple, brutish solution, can you just have movement of any block force all components to lose their powered status -- then start with the power source and slowly walk back through everything it's touching and reassign power / colors?

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image archelyte_vz · Apr 20, 2018 at 06:09 PM 1
Share

This actually proved to be the simplest, most effective method. $$anonymous$$y game is very conservation on runtime resources, so this method does not put any strain on gameplay.

There was initially a flickering issue with the animation resetting, but that was fixed with a condition IEnumerator and a 0.1f delay.

If you post this as an answer ins$$anonymous$$d of a comment, I'll accept it as the correct solution.

avatar image
0

Answer by DigiTranceG · Apr 18, 2018 at 03:26 PM

Maybe it has to do with the Singleton you are calling in the script?

 public static Wire_Moveable control;

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Bunny83 · Apr 18, 2018 at 04:34 PM

Well, it's not clear when you said "Replicating MC Redstone Wiring" what you actually mean. MC redstone wireing has a loss of energy each block it travels. This naturally let would let the energy "dry out" when any update happens to one block. Further more redstone updates due to minecraft's "block update". So when anything changes (like placing or removing a block) the neighbors get an update and should re-evaluate their state. Unlike most other mechanics in MC redstone does an actual search / floodfill through connected pieces. So when an update happens it would search for an actual energy source up to 15 blocks. If no source is found it will be disabled.


This can get quite expensive quite fast especially if you want to support longer chains than 15. Other mods which provide a wireing system (with no loss) usually build an actual network. Here the actual properation of a signal through the network doesn't matter. If a network has a source somewhere the whole network is triggered. The active attached sources may be registrated in a network so once all sources are gone the network will be off. Each time a block is placed or destroyed that is adjacent to an existing network / part of a network, the whole network will be re-traced again to determine which pieces are connected. Destroying a piece could split a single network into up to 6 new networks (In MC each block has max 6 neighbors).


Using triggers may work but if your game is actually grid based it would be way easier to actually check the grid neighbors. We have almost no idea of how your implementation looks like, how a user is able to place / destroy pieces. What kind of collider an piece has. If one piece can be connected to more than two other pieces. Where the power / energy comes from. ...

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Bunny83 · Apr 18, 2018 at 04:37 PM 0
Share

And now i'm busy since I'm currently breeding a redstone chicken in SkyFactory3 as well as prepearing real chicken legs for dinner ^^

avatar image archelyte_vz · Apr 19, 2018 at 06:40 PM 0
Share

To clarify things a bit then. I'm really wanting a directional energy flow that can be cut off. There is a defined source, and the energy can travel freely when connected to the source, but if one of the wires is removed, then all wires AFTER the break lose power.

Currently they don't do that. Each wire can successfully be powered after connecting to the source, and there is a check in the code to detect if they have lost connection with the power, which sort of works. The problem is that when two non-powered wires become powered, then one of them becomes a source and cannot be de-powered.

The wires are on a grid. Here is a better illustration of what is happening.

Desired Behavior: alt text

Actual Behavior: alt text

ppm-power-bug-01.gif (10.9 kB)
ppm-power-bug-02.gif (12.5 kB)

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

477 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

My Algorithm for checking whole tiles didint work 0 Answers

How to deactivate an object in array which was chosen randomly before then activate randomly another one also in that array? 1 Answer

How to stop a calling function 1 Answer

KEEP INSTANTIATE PREFAB ONMOUSEDOWN 1 Answer

Unable to make 2D enemy zigzag : Top Down View 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges