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
0
Question by Catfang007 · Apr 07, 2015 at 01:36 AM · spritedragsnapdrop

Coding Advice Needed: Building a 2D ship editor

I'm trying to build a 2D ship [in-game] editor, where a player will select parts from collection and assemble them in a drag and drop interface. A player will start with an initial part (say hull) that has hard points (attachment points) on it where other parts may be attached. These in turn may also have hard points where further part attachments may occur. Parts will "snap" to the hard points when dragged near them. The end result will basically be a tree (hierarchy) of parts, where the root node is the base part (hull in this case) and first children are the ones directly linked to the part, and each part having possible child parts itself. Eventually I want to let the player then use/fly the finished product.

I've gone through several tutorials (see below) on how to use the new EventSystem to allow for drag and drop, but I'm still at a loss on how to create the "hard points" or how to make the sprites "snap" to them. I'm able to create "slots" where parts could be placed using tutorials aimed at card games, etc., but nothing like what I'm trying to do where a dynamic object is basically being built up. I need a coding strategy that will allow me to create various prefab parts that can be assembled in limited ways. I feel like I'm really close, but I'm missing the final bit on how to script up the hard points and creating code to "snap" to these hard points.

TL;DR Version:

I need: A way to dynamically assemble 2D sprites into a dynamic object while retaining the assembly hierarchy.

My thoughts: Script (Class) with List of Points (or something more complex to handle orientation as well) defining what the valid connection points are, as well as handling the connection ("snapping to") of other parts. I'm not sure how to do this part. :)

Can anyone help me?

Tutorials used so far: "Unity UI Drag and Drop Tutorial" https://www.youtube.com/watch?v=c47QYgsJrWc

"UI PANES, PANELS AND WINDOWS" https://unity3d.com/learn/tutorials/modules/intermediate/live-training-archive/panels-panes-windows

Comment
Add comment · Show 1
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 LMan · Apr 07, 2015 at 03:00 AM 0
Share

I would suggest writing a "Ship-Part" class that includes a list of gameobjects. You could then make prefabs of each part and place empty gameobjects where you wanted the connecting points to be. Use the inspector to add those hardpoint objects to the list, and then you can reference the positions of the hardpoints through script.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by rageingnonsense · Apr 07, 2015 at 10:54 PM

Add empty gameobjects for your hard points and attachment points to the prefab. Then when dragging, check to see which hardpoint is closest. If you are within a certain distance of that hardpoint, snap the part's position to the correct location.

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.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Drag and Drop and snap between the edges! 1 Answer

Editor drag&drop override 1 Answer

UI drag and drop 1 Answer

Simple drag and drop - no physics 4 Answers

How to drag and drop in 2D game 0 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