Search Unity

How can i create conveyor belts with items on it in 2D top down

Discussion in '2D' started by Exthase, Oct 8, 2019.

  1. Exthase

    Exthase

    Joined:
    Feb 25, 2019
    Posts:
    6
    Dear Community,
    after a couple of days trying and researching, I think its time to ask our kind forum to help me with this.
    About me: I'am a programmer in education in Germany, for a company that develop online shops.
    I mean i have some experience with OOP, structures and can understand a lot of stuff with algorithm.

    I like to program some modular transportation belts for my game that are really like in factorio. But I stuck
    at the point how i would handle the items on the belt and how i should move them.
    I thought about some path or waypoint system that can be updates any time if the conveyor belt
    changes (building / destroying). Factorio has 2 item rows on the conveyor belts that are independent.
    If this makes no big changes to the normal one row behavior please take this in consideration.

    ATTENTION! The Camera view is top down and the game is 2D - something like Factorio

    The Code i need would be written in C#, but i would understand Javascript, C++, Java, PHP
    or some other modern languages as well.

    I saw a source-code of a game called: Mindustry - well made and has even Multiplayer, but i didn't understand the complex mechanic behind the item handling.

    If anyone can help me with this, not very simple question - i would really appreciate it.

    Thank you for reading
     
  2. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,769
    Hey.
    I have seen you PM. It is fine. But you could be a bit more patient and wait day or two before sending one, as someone could replay here in that time.

    Regarding belts and items, please check factorio blog post
    https://www.factorio.com/blog/post/fff-176
    It should give you some ideas to start of.

    It is worth to check also other blog posts.

    All best.
     
    Exthase likes this.
  3. Exthase

    Exthase

    Joined:
    Feb 25, 2019
    Posts:
    6
    First, thank you for your reply and for your time.
    The Problem I have at the moment is that I don't know how to manage the positions and/or path in unity.
    As a factorio lover I know almost every fff from it. I tried to understand the mechanic with segments and relative positions but I can't.
    If you or anyone else can help me out a bit.

    Excuse me for my impatientness.
     
  4. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,769
    Segment is just 10 tails of continuous belt components. When one segment ends, it passes products to next segment.
    Segmenting allows for better partition of the factory, specially when building and modifying belts.
    If you break one belt, or get destroyed by aliens, only these 10 tails in chain need be computed, rather whole link of 100s, or 1k+ tails.

    This is something you need figure out. Article rather explain concept nicely. Not sure what I can add to it more. Is neat concept. If is bit much, then just step back and start simpler.
     
    Exthase likes this.
  5. Exthase

    Exthase

    Joined:
    Feb 25, 2019
    Posts:
    6
    Thank you for your fast answer.

    Now I only need to know if there are any path tools in unity or if i must build everything from scratch. I really dont know how to check for collisions between items and the position.

    I have a conzept for the trail segement generation and for updating it on change but i can't think of a possbile way for a modular version of pathing it.

    I like to say thank you for your help so far. I think i could really read more or other blog post. Do you eventually know other or similar things to this problem?

    Thank you in advance for your time and sorry for my english.
     
  6. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,769
    I am not aware of such Unity assets for building factory alike. I know multiple people doing similar things. But each takes problem differently. Hence there isn't really single universal solution.

    Also people either don't want to, or don't have time, to write details on such mechanics. But something may be out there on internet.

    Collision / blocking of items on the conveyor belt concept was mentioned in the link. It basically checks the distance to next item.
     
    Exthase likes this.
  7. Yoreki

    Yoreki

    Joined:
    Apr 10, 2019
    Posts:
    2,605
    If you plan on creating a game similar to Factorio in that there can be tens of thousands of things (items, robots, machines, ..) on the world of even screen that the same time, then one of your main concerns will be performance optimization, which is a pretty advanced topic in itself. Of course, start by creating a prototype to get your head around the ideas described in the fff Antypodish linked. I agree that it explains the ideas involved very well, so you just need to take a good, long look at it, and try to break it down into chunks you can understand, and then start experimenting around with it.

    After you are done with understanding the idea behind conveyors, and if you create such a game that needs very good optimization, then you may wanna look into DOTS as well. This adds a lot of complexity, especially for a beginner, but if you want tens of thousands of "things" to run smoothly, then it's pretty much your only option at some point. Needless to say, if you create a game where you only work with a couple hundred things at max, then this wont be necessary.
     
    Exthase likes this.
  8. Exthase

    Exthase

    Joined:
    Feb 25, 2019
    Posts:
    6
    Thank you both for your answers.
    I will need to take my time with it.
    I think I have now an other perspective on this project and your answers show me that i need to start small enough that i can understand what i need to do.

    I will eventually come back if I have a more distinct problems with some mechanics.

    Thank you for your time, it really helped me out.
     
    Yoreki likes this.