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 inkspot · Dec 23, 2013 at 03:24 PM · rotationtransformpositionscaleorientation

[solved] Get upward orientation of object and add scale value

Hey community, so i have been trying to tackle this problem which is basicly a how to question. i am trying to move an object to the edge of another object, i almost got it to work except for a 'minor' orientation problem, this is the code snippet:

 currenthelditem.transform.localPosition.y = Vector3.up + snaptarget.parent.transform.localScale.y * 2;

of course the above doesn't work but it shows my intentions :) so basicly my question is how do i use the up orientation of the 'snaptarget' transform and add the localscale value to it. any ideas ?

Comment
Add comment · Show 2
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 robertbu · Dec 23, 2013 at 09:15 PM 0
Share

A couple of random suggestions. $$anonymous$$ake sure that the pivot point for all the objects is where you expect, and make sure all objects are scaled (1,1,1) with consistent rotation. This can be done in a 3D authoring program, but it can also be done in Unity with some editor scripts:

$$anonymous$$oving the pivot:

http://wiki.unity3d.com/index.php?title=SetPivot

Fixing scale and rotation:

http://answers.unity3d.com/questions/561786/how-to-export-obj-from-editor-with-rescaled-mesh.html

Note the second editor script makes a clone of your object at it current scale and rotation resulting in an object with scale (1,1,1) and rotation (0,0,0).

avatar image inkspot · Dec 23, 2013 at 09:33 PM 0
Share

Thanks for the suggestion, but i started out already extra carefully with neutral placeholders all evened out, in order to avoid such problems. this problem is really related to getting the size/scale of the object creating a correct offset.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Statement · Dec 23, 2013 at 04:16 PM

I have no idea what the code is trying to do but here is my best guess.

You want to position currenthelditem two units local above snaptargets parent.

 var item = currenthelditem.transform;
 var parent = snaptarget.parent.transform;
 item.position = parent.TransformPoint(Vector3.up * 2);

Send a comment if this is not what you meant and please clarify.

Comment
Add comment · Show 8 · 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 inkspot · Dec 23, 2013 at 05:28 PM 0
Share

Thanks for your reply! this is almost, what i'm trying to do, except, ins$$anonymous$$d of the two units i want to base this offset on the scale of the 'snaptargets parent' maybe my image helps to visualize it alt text

graphic.jpg (113.5 kB)
avatar image Statement · Dec 23, 2013 at 05:46 PM 0
Share

So you want to rotate the chimney looking dragged object, and snap the top (well, bottom, upside down) of the chimney. The goal is to line the chimney up perfectly with the lower node of the funny onion shaped snowball?

(Is this a Christmas Game btw? :))

avatar image inkspot · Dec 23, 2013 at 06:06 PM 0
Share

Lol, i haven't looked at it that way in terms of xmas, i wanted to make simple but distinct shapes to see the changes it makes before adding real models on the working code. The third image shows what happens when i snap the 'chimney' on the lower node, it should do the same as it does on the second image but upside down. it gets its rotation from the nodes, so for rotation it works, but the offset doesn't work as the image shows, what i need is to add the offset(scale of the target) based on the direction of the node.

avatar image inkspot · Dec 23, 2013 at 06:21 PM 0
Share

It think this question is solved i used @statement code and changed it to:

   var item = currenthelditem.transform;
 var parent = snaptarget.parent.transform;
 item.position = snaptarget.transform.TransformPoint(Vector3.up * snaptarget.parent.transform.localScale.y * 2);

The orientation works correctly now, except for scaling, but thats another issue.

avatar image Statement · Dec 23, 2013 at 06:29 PM 0
Share

You may want to set localScale of item to the lossyScale of snapTarget or parent. Not sure if that would solve it.

I thought for a while that the onion shape could have been Santa Claus' Bag of Gifts, but I hear what you say. It's useful to have mocks and it's a nice break from boxes, capsules and cylinders :)

Show more comments

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

19 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

Related Questions

postion scale and rotation greyed out and not working 1 Answer

Quaternion rotation with normals bug: Only works into one direction? 1 Answer

The way to approach DodgeRoll 0 Answers

why is my object's rotation affecting it's position? 1 Answer

how to CORRECTLY position and rotate a gameobject in unity 2 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