Thursday, May 10, 2018

How to align “tracks” or modular objects in Unity ?

Leave a Comment

I'm developing a simple game, where user can place different but modular objects (for instance: tracks, road etc).

My question is: how to match and place different object when placed one near the other ?

My first approach is to create an hidden child object (a box) for each module objects, and put it in the border where is possible to place other object (see my image example), so i can use that coordinates (x,y,z) to align other object.

But i don't know if the best approach.

enter image description here

enter image description here

Thanks

2 Answers

Answers 1

Summary:

1.Define what is a "snapping point"

2.Define which is your threshold

3.Update new game object position

Little Explanation

1. So I suppose that you need a way to define which parts of the object are the "snapping points". Cause they can be clear in some examples, like a Cube, where the whole vertex could be snapping points, but it's hard to define that every vertex in amorphous objects.

A simple solution could be the one exposed by @PierreBaret, whic consists in define on your transform component which are the "snapping points". The other one is the one you propouse, creating empty game objects that will act as snapping points locations on the game object.

2.After having those snaped points, when you will drop your new gameObject, you need to define a threshold, as long as you don't want that every object snaps allways to the nearest game object.

3.So you define a minimum distance between snapping points, so if your snapping point is under that threshold, you will need to update it's position, to adjust to the the snapped point.

Visual Representation:

enter image description here

Note: The Threshold distance is showing just ONE of the 4 current threshold checks on the 4 vertex in the square, but this dark blue circle should be repilcate 3 more times, one for each green snapping point of the red square

Of course this method seems expensive, you can make some improvements like setting a first threshold between gameobjects, and if the gameObject is inside this threshold, then check snapping threshold distance.

Hope it helps!

Answers 2

Approach for arbitrary objects/models and deformable models.

[A] A physical approach would consider all the surfaces of the 2 objects, and you might need to check that objects don't overlap, using dot products between surfaces. That's a bit more expensive computing, but nothing nasty. If there is no match involved here, you'll be able to add matching features (see [B]). However, that's the only way to work with non predefined models or deformable models.

Approaches for matching simple and complex models

[B] Snapping points are a good thing but it's not sufficient alone. I think you need to make an object have:

  • a sparse representation (eg., complex oriented sphere to a cube),
  • and place key snapping points,
  • tagged by polarity or color, and eventually orientation (that's oriented snapping points); eg., in the case of rails, you'll want rails to snap {+} with {+} and forbid {+} with {-}. In the case of a more complex object, or when you have several orientations (eg., 2 faces of a surface, but only one is candidate for an pair of objects matching) you'll need more than 2 polarities, but 3 different ones per matching candidate surface or feature therefore the colors (or any enumeration). You need 3 different colors to make sure there is a unique 3D space configuration. You create something that is called in chemistry an enantiomer.
  • You can also use point pair features that describes the relative position and orientation of two oriented points, when an oriented surface is not appropriate.

References

Some are computer vision papers or book extracts, but they expose algorithms and concepts to achieve what I developed in my answer.

  1. Model Globally, Match Locally: Efficient and Robust 3D Object Recognition, Drost et al.

  2. 3D Models and Matching

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment