• 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 hardmode2236 · Nov 21, 2014 at 03:48 AM · cameratransformpositiony

moving a transform by 10 but it goes exra...

this has me totaly stumped.

im telling my camera to move down 10 like so:

 function initCam()
 {
     cam.transform.position.y = -10;
 }

and for some reason when i test the app it goes from 0(its starting Y position) to -11.10805. i cant imagine why it would blatantly ignore what i have written in the script.

here is how its called:

 function OnGUI () 
 {
     if(totalTargets == 1)
     {
         if (GUI.Button(Rect(Screen.width*.1, Screen.height*.45, Screen.width*.15, Screen.height*.05), "Initialize"))
         {
             initCam();
             for(t in TargetedTargets)
             {
                 if (t == true)
                 {
                     targets[c].initNow();
                 }
                 c++;
             }
             c=0;
         }
     }
 }


side note: when i try to put it back to 0 using cam.transform.position.y = 0; it goes to -1.108051 instead. so far this is the first piece of code for moving the camera in this project. so it cant be any interference from any other scripts.

  • forgot my unity was out of date, could be some kind of error. i'm going to update and restart my PC or something, see if that fixes it.

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
1
Best Answer

Answer by jtok4j · Nov 21, 2014 at 07:16 AM

Hi Hardmode2236,

I recently lost some hair with this same issue... I was pulling my hair out, trying to figure out what the #)*(WGN was wrong with my coding...

It turned out that "After" I started playing my scene, the position of the object that I was moving with transform, actually was changed from where I thought it was.
It was a child object of a larger prefab, if I remember right.

So, it went like this: Object's transform y position was set at 0.
When I clicked "play" (that button) in the editor, I then went to the inspector, and saw my object's (the one I'm transforming) position (y) was not at 0 anymore, due to the placement of the parent object/prefab.

So, try to check and see if your object's run-time position is actually adjusted after the scene starts up. :)

Hope this helps.

Comment
Add comment · Show 2 · 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 hardmode2236 · Nov 21, 2014 at 07:24 AM 0
Share

ahhh yess, thats it. my 'world' object which is a parent to all objects in the scene wasn't at (0,0,0). i set it right, now my camera is perfect. thanks for the insight :)

avatar image jtok4j · Nov 21, 2014 at 07:25 AM 0
Share

Sweet! :D

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

27 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

Related Questions

Finding the limits of transform coordinates 1 Answer

Changeing Camera Position 1 Answer

Set Game Object Position to Sides of a Camera 1 Answer

How to make Camera position Independent of its Rotation? 1 Answer

how to move an object towards way position only ? 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges