Search Unity

Need advice in Making an interactable Wall

Discussion in 'Editor & General Support' started by diegopetrola, Jun 9, 2020.

  1. diegopetrola

    diegopetrola

    Joined:
    Feb 29, 2020
    Posts:
    4
    Hello everyone!

    I am making a simple game where a ball bounces around and the player can use the mouse to make a wall that will change the ball's path. Below is a simple video that shows how I intend things to work.
    To make the wall, I am instantiating a lot of prefabs of a simple cube. To make things faster, I load all the cubes and put them behind the "arena" when the game starts. When the player creates the wall I simply move the cubes forward (I assume this is faster than instantiating and destroying the objects on the fly).

    The problem is: to make the wall more smooth (you can see in the video that the wall is too edgy) I need to create a lot of cubes, at least 100 on each row and another 100 on each column. That is 10.000 cubes on the entire arena! The game starts to lag if I do that. I imagine this is not the clever way to do that because this seems to be a simple matter, so I would be glad for any adivice on how to deal with this and make this simple game faster and smoother.

    Thanks everyone in advance! :)
     
    Last edited: Jun 10, 2020
  2. I would try to draw lines with the LineRenderer ( https://docs.unity3d.com/ScriptReference/LineRenderer.html ) and matche the sections with simple colliders. It would 100x faster than 10k cubes in game object mode.
    If you actually want to build a custom solution, then I recommend to sink in a little bit deeper. Catlike Coding has an excellent tutorial (he has more, but this is especially excellent) where he creates custom meshes for hex maps, but you can adopt the same concepts to your sections: https://catlikecoding.com/unity/tutorials/hex-map/part-10/
     
    diegopetrola likes this.
  3. diegopetrola

    diegopetrola

    Joined:
    Feb 29, 2020
    Posts:
    4
    @Lurking-Ninja, while browsing through your links I found a lot of helpful stuff! I still need to make some tests but I believe the problem is solved now. I am using a mesh full of vertex and moving the vertex around coupled with a Mesh Collider.

    Thank you very much for your help!
     
    Lurking-Ninja likes this.