Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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 /
avatar image
4
Question by eurobrew · Dec 15, 2010 at 01:32 AM · vertexsnapping

Procedural Vertex Snapping

I'm wondering if there is a way to perform Vertex to Vertex snapping within a script (procedurally). I know theres one in-built in the Unity3 Editor, but I need to generate/instantiate my levels dynamically on load. Essentially I have a bunch of track pieces that I want to piece together in a randomized fashion, getting a different track each time.

Are there any scripts out there for something like this? Or is it something I'd have to script by manipulating each objects mesh, making the vertices of the two objects meet?

Cheers

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

1 Reply

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

Answer by Statement · Dec 15, 2010 at 01:58 AM

I propose a simple method that doesn't manipulate meshes at all.

  • It requires your meshes already to be modeled in a manner that allows track blocks to be placed adjacently without having to edit vertices.

For every track (block) you have, you can add a number of empty game objects with a unique tag, such as "snap point" to indicate that another block can be placed there - extending the track. Each block should have a common origo or root node that will place the track model perfectly for every track part you have if they have the same world matrix. Then it's a simple matter of placing the next block exactly on the position, rotation and scale of the nearest snap transform. Doing so will allow you to build complex tracks effortlessly.

  • Some caveats to consider is that you should check the nearest snap transform if it is child of the transform you're currently moving, so you don't try to snap onto the new track you're placing.

  • This method require that all tracks have a similar start and end structure, but can vary in direction, length and can even have forked tracks.

  • You must naturally flag if a snap point already is occupied with another track so you can't place two tracks on the same snap point.

I hope this helps. Think simple. :)

Comment
Add comment · Show 2 · 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 eurobrew · Dec 19, 2010 at 07:11 AM 0
Share

I have created some waypoints for the track, and your solution works great. Except that using the code: path.transform.position = snapFront.position; Gets me into a pickle, where obviously the path's center shouldnt be the next snap point, but the snapFront and snapBack should be in the same position. How could I set the position of the path so these two points meet?

avatar image Statement · Dec 19, 2010 at 07:48 AM 0
Share

It sounds like you have a setup where the "path" has a child called snapBack, and snapBack should snap to location of snapFront? path.transform.position = snapFront.position - snapBack.transform.localPosition;

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.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Modifying vertices values in a mesh 1 Answer

Problems with vertex snapping, 2D peoject Unity 5 1 Answer

Vertex snapping while resizing 1 Answer

How to Vertex-Snap the corner of a Sprite-Shape 3 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges