• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by Graywolf212 · Oct 10, 2016 at 12:06 AM · gameobjectspositioningsnappingfaces

Can I snap a game object to the face of another similar to vertex snapping?

Say I have a cube in the scene, and I create a child empty game object for it. I can use Vertex Snapping to snap the empty game object to any of the 8 vertexes of the cube, but I want to be able to snap the game object to any of the midpoints of the edges or midpoints of the faces as well, and also the center of the cube, giving 27 options instead of 8. Is this possible? Thanks!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by conman79 · Oct 10, 2016 at 12:51 AM

You'd need to write a custom editor script to be able to do that for a primitive cube, ie. 8 vertices.

A workaround solution would be to use 8 smaller child cubes under your parent cube. You could then use the child cube meshes for vertex snapping only, and the parent cube for rendering/colliders etc.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Geometrical · Oct 10, 2016 at 05:13 AM

Have a look at the Mesh class which states that it can create and modify meshes. If I'm correct, you should be able to calculate the points of a face and subdivide it to get those extra vertices. Though I'd warn you that this can take a toll on performance.

Alternatively you could write a MonoBehvariour script which utilizes the [ExecuteInEditMode] attribute (which does what the name implies, of course). In the script you could perhaps cast a ray onto the face of an object and get a point on the face of the object to snap to. This requires the object to have a a collider, which isn't ideal.

All this vague, but I hope it helps.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

77 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Positioning Screen Space UI element in center of a grid square? 1 Answer

Dynamic sorting objects on terrain 0 Answers

How to make gameobject appear in center of camera irrespective of it's side?? 0 Answers

Create GameObjects and move them from JSON data 0 Answers

How to handle snapping to an "anchor" point? 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges