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 1337GameDev · Dec 18, 2013 at 07:26 AM · objectchildmovetranslateoffset

Using gameObject.translate moves it farther than expected

I have a setup using ngui where I want to use the camera to make a gui, but whenever i called Translate on a child of "UI Root" it moves very far.

My current setup have my "UI Root" set at the origin, and other menu's move the camera left or right to navigate menus. Whenever I select a menu (move right and move a menu into where im going to move my camera), I call translate on the child gameobject of "UI Root" that I want to select as a menu to display and navigate to.

My problem is when I call translate(screenSize*numberToMultiply) it move it over a lot, and it seems to negate it. I call:

uiObject.transform.Translate((screenResolutionWidth*offsetFromTitleMenu), 0,0);, where my width is 350 and my offset is 1, and it moves it to -56000 on the x axis (it is expected to move on only the x-axis).

Why would the child object move so far when I tell it to translate only 350 units left or right? I also look at the scale and multiply the 350 by the scale to compensate, but this also move it the -56000 units. Why would it use this?

Comment
Add comment · Show 10
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 1337GameDev · Dec 18, 2013 at 08:26 AM 0
Share

It is 1.0. When it is different (I check in the inspector), I multiply this scale by the value I want to move by (as this s the screen width and also the world units) i want to move over by.

I call this once during a function call when a button is clicked (using NGUI on Onclick method)

avatar image robertbu · Dec 18, 2013 at 08:32 AM 0
Share

Well you shot down my idea, and probably @fafase's as well. Just for testing purposes, try removing your Translate() and replacing it with:

 transform.position += Vector3.right * 350;

if it is Javascript you can do this ins$$anonymous$$d:

 transform.position.x += 350;

Note these are bit different than Translate() since Translate() by default uses local coordinates. But it might give more insight into the problem.

Just for kicks, add a Debug.Log() to make sure the code is only getting called once.

avatar image 1337GameDev · Dec 18, 2013 at 08:37 AM 0
Share

The debug log is only outputting once. I want to use translate. The position setting works fine for what I want, but I want to tween this over x number of seconds and translate is easiest for this.

avatar image 1337GameDev · Dec 18, 2013 at 08:43 AM 0
Share

i use this following code:

guiCam.transform.Translate((screenWidth*sCam),0,0, Space.World);

where guiCam is my gui camera that I move, and sCam is the current scale of my camera. Tbis should work, but doesn't. If I change Space.World to Space.Self, it doesn't change anything.

avatar image fafase · Dec 18, 2013 at 08:45 AM 0
Share

is OnClick method working when you press down or when you press?

Show more comments

1 Reply

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

Answer by 1337GameDev · Dec 18, 2013 at 07:41 PM

I solved the problem. The parent object had a scale of 0.000625, which made me moving 350 units into a lot further (as translate calculates to world coords and scales up to scale 1.0).

I just multiplied the parent gameobject's scale against how many units I wanted to move, and it positioned the child where I wanted it.

I wish unity would have this kind of information in the documentation.

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

17 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

Related Questions

Translate object on y axis 0 Answers

How to translate object using script? 1 Answer

How to move a specific texture from a shader? 0 Answers

Moving Object by touching it? 1 Answer

How can I move a corresponding object. 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