Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Start Advice for a Vehicle Building Game

Discussion in 'Game Design' started by Andy1UP, Jun 27, 2016.

  1. Andy1UP

    Andy1UP

    Joined:
    Jun 27, 2016
    Posts:
    2
    Hi, I just need a little advice on how to start a vehicle building physics game something like besiege or scrap mechanic just a game example. the question is how would i get to starting it out with a center block or some other way which way would be the best. Any other advice will be appreciated as i am quite new to unity but not to programming.
     
  2. Reaven99

    Reaven99

    Joined:
    Oct 3, 2015
    Posts:
    39
    Hi,

    I have made an engine like this some time ago which works pretty smooth.
    I created the blocks like this:
    A collider on each side of the block to check for raycasts of the mouse.
    I did this so i could check wether the player is aiming at it.

    Now you now what side of the block you need to spawn another block, Simply instantiate and use the "LookAt" function to look at the block you were aiming at and place it with an offset on the Z axis.
    This system can be used for any block you want like wheels,armor,cannons etc.

    With this kind of system all you have to do is create box colliders on the blocks/pieces in order to being able to place a new block, which gives you alot of possibilities.

    The thing with these kind of games is the physics, i started out with giving each block a rigidbody.
    I did this so i could explode the vehicle and the blocks would be flying everywhere, this is pretty neat for sure but performance wise it was really bad.
    For a small vehicle it has no performance issues but people dont want small vehicles they want something with 100+ blocks etc, and if they can multiple of those vehicles.

    My fix for this issues was pretty simple, i created a parent and added a rigidbody to it.
    No more rigidbodies for each block, but instead i added animaties and particle systems to the blocks so if they got destroyed they would still fly and burst into small particles.

    Regards
     
  3. Stepan_123

    Stepan_123

    Joined:
    Jul 14, 2017
    Posts:
    1
    Hello, my question might be silly, but, anyways, how to store information about that vehicle so that player can have a collection of machines? I know about JSON, and I am more interested in the file structure and "reconstructing" algorithm. Thanks.
     
  4. Serinx

    Serinx

    Joined:
    Mar 31, 2014
    Posts:
    788
    @Stepan_123 Good that you know about JSON. You can use JSON to store all the relevant information about each machine that you've create and each component that belongs to that machine.

    I imagine you'd store all of the components as JSON objects in a JSON array.
    Each one would store an ID, the local position, the component name, and the ID of the thing it's connected to.

    You can use Resources.Load to retrieve the component using its name and instantiate it at the correct position, relative to the central object.

    You would use the parent ID to find the component that this one is connected to and do any joint connections that are required e.g. fixed and wheel joints.

    The connection code should be pretty much the same as your runtime code (minus the user input) so make sure your separate that code accordingly.

    Hopefully, that points you in the right direction!
     
    Stepan_123 likes this.