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 magnusm · Jul 16, 2013 at 08:06 PM · javascriptcustomizationmodules

2D Modular Customization With Snapping

Hey :)

This might be quite a long and ambiguous question to ask, but after looking around a lot I am still pretty stuck so I'll just give it a go anyway :P

The general idea is that the user can click on a module and drag it onto his space ship, to customize it. I am only working on a 2D plane from above, and all the modules at the moment are square with 4 or less connectable sides. The modules will all provide different benefits, and have different requirements. Also just to say that I am writing this project in Javascript :P

Specific tasks I could do with help on:

  • Picking up and dragging the modules using the mouse.

  • Placing these modules onto the ship using a grid, so they snap to the other modules.

I honestly have no idea where to begin a task like this, so any help from relevant articles would still be appreciated. But help with the actual writing of the script would be a most useful to me.

Thanks for your time, Magnus :)

Comment
Add comment · Show 6
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 DavidDebnar · Jul 17, 2013 at 03:16 AM 0
Share

Java or JavaScript?

avatar image magnusm · Jul 17, 2013 at 11:34 AM 0
Share

Awesome cheers $$anonymous$$ark, that breaks it down nicely. I'll have a thorough read through of that when I have got time later. I'll get back to you, to let you know how I get on :P

Also $$anonymous$$, I meant Javascript. Apologies, I sometimes shorten it to Java forgetting that it's a different thing

avatar image magnusm · Jul 18, 2013 at 04:09 PM 0
Share

Finally, after a large amount of ball-ache, I managed to do it! :)

Just going to say now, if anyone else looking at this in the future wants to do a similar thing, I can put the scripts up for you.

I just cannot be bothered right now :P

avatar image markedagain · Jul 18, 2013 at 04:14 PM 0
Share

its always simple once u wrap your brain around it ;) gl with the rest

avatar image JesseK · Sep 01, 2013 at 10:23 PM 0
Share

Hello magnusm, would you please post your code or pm me with it. I would really appreciate it!

Show more comments

1 Reply

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

Answer by markedagain · Jul 17, 2013 at 03:46 AM

ok , ill post as comment cause im being lazy to use actual code and i use c#, but i will explain the logic.

so first thing to tackle is your mouse click, the easiest to get going but less favorable is the OnMouse event function attached to the dragable objects. the other would be a single script checking for mouse click and then sending out a raycast from screenToWorld. the latter is favorable because it will help traverse layers and allow u to select objects behind other objects ( ex: your outside transparent wall )

now you have a few choices using the mouse events, prob the simplest to get u going is using the OnMouseStay witch is fired off as long as your mouse is over the object, you shoujold first check if the mouse button is pressed , if so then we are in "drag" mode. from this point you need to start changing the transform.position to match the position of the mouse. in retrospec, u will still have to use a screenToWorld at this point just to get at least the 2 coords out of the mouse. so as long as button is pressed and mouse is over object, keep changing the transform.

once you get all this done, you will now have to get your "snapping" working, for this is relatively simple, only change your transform.position of your object, when the mouse has past half the distance u want to snap to, ie your invisible middle point where u snap to next tile. to figure out exact coord, try to see if u can figure it out, i always use the modules function for this ( 16 % 4 = 0 ) but this is a bit tricky for some, and i cant remeber the longer version off the top of my head.

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.

Follow this Question

Answers Answers and Comments

20 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

Related Questions

Multiple Cars not working 1 Answer

Setting Scroll View Width GUILayout 1 Answer

Can someone help me fix my Javascript for Flickering Light? 6 Answers

setup a php master server 2 Answers

Need help with WeaponSwitch Script 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