Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by sniper02311 · Jan 17, 2019 at 03:40 PM · transformscripting beginner

[SOLVED] localScale movement in 3d world space coordinates WITH scaling

So, I have been doing a LOT of testing on snapping objects together in realtime, and incorporating scaling of all the 3d vectors at the same time while having them try to still snap respective to scale.

This, as many I have read about, has been a big issue since devs seem to scale in script based on localScale (easy to do). Then, there is talk about transferring local to world scale, pos, etc.

That actually became confusing to me, even though I love math and use it every single day in hobby. So, I decided to use the numbers and might have found an easy way to figure how to do what I need to do and it might be helpful if anyone can prove it works (in science, 3 of the same conclusions are required to confirm a theory, so Ill take at least one if possible lol).

Here is the idea: 2 game objects Each have the ability to detect 6 axis collisions (take the cube for example since its an easy poly with hard corners). So, placing one "cube" to the left of another, it will detect a collision at a specified distance. All good. Now, we can use that collision to move the active object to the inactive one (i.e. snapping effect).

To do this, we need world coordinates since local coordinates are a division of such in the open world of unity3d as I have found. But, there might be a most simple way even with scale in play.

Each cube say is vector3(1,1,1) localScaled. So, snapping would be easy using the TranformPoint option in Unity. It would tough edge to edge perfectly since both are 1:1.

When scaling however, things start to either oerlap, or not reach far enough DUE TO the scale differences.

Can anyone verify this is a solution: Take the distance from centerpoint of the inactive object to the edge of collision (i.e. 1/2 dist of axis). THen, I find that the active object uses center point also, and if you go from centerpoint to centerpoint, and active object is larger, the active object will overlap, right? ANd if smaller it will not even reach inactive obj.

So, just find the 1/2 axis magnitude of inactive, and the active object can be calculated to snap that distance +/- (depending on left/right relationships) added to 1/2 axis of the active object? That way, the active object will hit its centerpoint on the edge of the inactive object, and then move the additional 1/2 axis magnitude of itself in the same direction to be finally on the edge of the inactive object, smooth as butter, no matter the scale.

Here is a diagram I made that should show what this means: alt text

What are the thoughts on this and does this make sense? I am not great at explaining things but Ill answer anything confusing or questionable. Just wanted to try to make something easier and think I found "a" way as far as scripting goes, I can only assume. SO, what would be a good formula that would fix the example in the pic to get A next to B regardles of scale, using the distance lines I shown? Because, I found that "locally" scaling, causes this diagram to happen in "world" positioning.

Hope that makes sense :/

neededformula.jpg (82.1 kB)
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
0

Answer by sniper02311 · Jan 19, 2019 at 04:47 AM

ANSWER: I found out how to do this just using the TransformDirection formula and adding scale into its Vector 3 positioning.

So, in the pic above, and this also takes into account both scale factors of local objects transform, that the formula to make A next to B and stay there even if scaled (e.x. in the front of B on blue axis), the formula would be:

 objA.transform.position = objB.transform.position +objB.transform.TransformDirection(new Vector3(0, 0, (-objB.transform.localScale.z/2) - objA.transform.localScale.z/2));


if gameObject A is calle objA, and gameObject B is called objB.

Hope this helps someone someday.

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

197 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 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 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

How to reset camera rotation/ position after "Free look"? 0 Answers

Creating a camera controller for isometric view - Positioning the camera 1 Answer

Check if rotation if facing towards a vector3 0 Answers

transform.forward with rotation offset variable? 1 Answer

Resetting my cannon fire to its original transform 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