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 milint33w · Sep 09, 2012 at 11:19 PM · transformposition

How do you set the initial value of a variable to an objects current position in unity?

I am scripting in c# and I can't seem to find a simple way to set the value of some variables I made, X, Y, Z to the position of 3 spheres I made in unity. I will be manipulating the position of the balls using the script and keybinds but when I run the program I want the balls to be where I put them in 3d space within unity, not at 0,0,0. I tried not assigning a value to them upon declaration and instead doing it under the start method because it won't allow me to use transform.position.x where the variable is declared (at the top just inside the class and before the first method). This gives an odd result where they seem to be in the right relative positions but not facing the same way relative to my camera, as if they were all rotated together. I suppose that's something to do with world vs local axis, but I shouldn't have to worry about that so I'm using the wrong strategy.

Thanks.

 float throttle = 0f, count = 1;
     public double mass = 1, throttleCoeff = 0.25, Y, X, Z, adtGravity = 0;
     double gravityF = 0, Vy = 0, Vx = 0, Vz = 0, adtThrust = 0, accelywg = 0, accely1 = 0, accelx1 = 0, accelz1 = 0, accely2 = 0, accelx2 = 0, accelz2 = 0, accely3 = 0, thrustF;
 
     // Use this for initialization
     void Start ()
     {
         Y = transform.position.y;
         X = transform.position.x;
         Z = transform.position.z;
     }
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 RetepTrun · Sep 10, 2012 at 01:46 AM

I'm not totally clear on what you're trying to do but maybe add some more variables to hold the rotation of the objects. RX=transform.rotation.x

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

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Setting Position of Spawned Prefab 2 Answers

gravity causes transform.position not to work 0 Answers

Offset against Rotated Object,Applying Offset to a Rotated Transform 1 Answer

Is mousePosition not equal object.transform.position? 0 Answers

How to make object stay certain distance above ground (relative o ground normal) 1 Answer


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