x


Snapping Walls Together

Hello, I'm brand new to Unity and I am trying to create a construction type game.

What I want is to be able to create walls in game and be able to place them wherever according to a grid system. What really gets me is how to make it so that the walls snap together well to create fluid corners (90* is fine) or "T" or "+" intersections.

I understand that this type of snapping together requires a grid based game.

I would Also like to be able to create walls this way in game as well as in the editor, is that possible?

I'm no expert at scripting, so I could really use the help, Thanks a million

more ▼

asked Jan 29 '11 at 10:33 PM

OptimusRhyme gravatar image

OptimusRhyme
31 1 1 1

Regarding the visual aspect, is it rendering artifacts at the seams due to numerical imprecision that you're wondering about? Or are you just asking how to place objects on a grid in general?

Jan 30 '11 at 03:32 PM Jesse Anders
(comments are locked)
10|3000 characters needed characters left

5 answers: sort voted first

Without an understanding of a scripting language you are going to have a difficult creating a form of procedural or user created content system. This type of system is going to heavily integrate into how you store and interact with your map through out the game.

That being said, I would recommend going with a simple tile approach for generating and managing the map. I've implemented this in a couple ways and it has worked well for me.

Sharing an entire script implementation here would be tough, but I can cover the concepts.

Define the size of your game space grid (ie. 30 tiles by 30 tiles) Then you box this area in with a static object (or dynamically created if your size changes). Easiest being to start your map at 0,0 and expand positive in the X and Z directions.

Once you have that you need to define what your Tile Scale is. Tile Scale would refer to the size of a 3D object that takes up 1 tile. For example if your tiles are 3.0 by 3.0 units that would be a 3 tile scale. If they are 1 by 1 then it's 1. Your 3D models should fit that tile scale, ie. a wall is Tile Scale units by Tile Scale units.

Having this value you can easily convert from World Space (3d X/Z) to Tile Space (2d X/Y). World Space to Tile Space is dividing the X/Z by the Tile Scale; reverse is multiplication. When a user interacts on a space and you perform a Raycast you receive back the 3D point, you translate to Tile Space, and work with your data, and can easily go back and forth from Tile Space to World Space.

Most tile systems would store their tiles in a 1 or 2 dimensional array, and keep it synchronized with the 3D game objects. Others might create the array at runtime for procedural generation, or others might have an array to start with and build the 3D world and then drop the array. It all depends on what data you need to store in the tile, and if the gameObject can store that data instead.

Wish I could provide more implementation details, but the scale/scope of it seems quite large.

more ▼

answered Apr 16 '12 at 04:33 AM

Atrius gravatar image

Atrius
152 1 3

(comments are locked)
10|3000 characters needed characters left

How about getting this kind of snapping to occur during runtime?

more ▼

answered Aug 29 '11 at 06:37 PM

jasonbelmonti gravatar image

jasonbelmonti
-4

(comments are locked)
10|3000 characters needed characters left

Also, If each wall has its own collider then as the walls connect to each other the colliders must not touch or you have a constant collision and the wall colliders will not respond correctly to other impacts.

more ▼

answered Apr 16 '12 at 04:10 AM

overunity3d gravatar image

overunity3d
31 12 15 20

(comments are locked)
10|3000 characters needed characters left

Perhaps you could try creating a "Tile" system. It works well with the grid system you want to use. You would instansiate gameObjects according to an array, which would keep the x,y,z positon/rotation/scale and the object in the "tile".

more ▼

answered Aug 29 '11 at 07:35 PM

Illogical-Ironic gravatar image

Illogical-Ironic
121 3 4 8

(comments are locked)
10|3000 characters needed characters left

Under edit, in Unity, there is a setting called snap settings, that will work in the editor, not in game.

more ▼

answered Jan 29 '11 at 10:48 PM

AVividLight gravatar image

AVividLight
1.9k 68 100 128

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x10

asked: Jan 29 '11 at 10:33 PM

Seen: 1311 times

Last Updated: Apr 16 '12 at 04:34 AM