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 /
avatar image
0
Question by rob241abc · Dec 13, 2016 at 02:10 AM · c#gameobjecttransform.position

GameObject.transform.position on the y axis keeps changing even though object is stationary

Hello all,

I have a script that goes through all the objects with the tag "VehicleComponent" and then adds the object's position, rotation and scale to lists storing information about the object. However, the float for the object's position keeps changing to values near to the object's actual y position (usually within 3 either way), but not the exact value. The object is always stationary and when I make each object print it's position every frame, it shows that the object is indeed stationary.

Here is the relevant code:

   class VehicleComponents {
             public enum Types {Cube, Wheel};
             public static List<Vector3> localPosition = new List<Vector3> ();
             public static List<Quaternion> localRotation = new List<Quaternion> ();
             public static List<Vector3> localScale = new List<Vector3> ();
             public static List<Types> type = new List<Types> ();
         }

 public void Save () {
         GameObject[] _vehicleComponents = GameObject.FindGameObjectsWithTag ("VehicleComponent");
         foreach (GameObject vehicleComponent in _vehicleComponents) {
             VehicleComponents.localPosition.Add (vehicleComponent.transform.position);
             VehicleComponents.localRotation.Add (vehicleComponent.transform.rotation);
             VehicleComponents.localScale.Add (vehicleComponent.transform.localScale);
             if (vehicleComponent.transform.name == "Cube(Clone)") {
                 VehicleComponents.type.Add (VehicleComponents.Types.Cube);
             } else {
                 VehicleComponents.type.Add (VehicleComponents.Types.Wheel);
             }
         }
     }

Does anyone have any suggestions of what might be the cause and how to fix the problem?

Thanks in advance

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 Yoshinator2 · Dec 13, 2016 at 02:27 AM 0
Share

Do you have any other objects with that tag in the scene that are moving? The line I am talking about is:

  GameObject[] _vehicleComponents = GameObject.FindGameObjectsWithTag          
  ("VehicleComponent");
avatar image getyour411 · Dec 13, 2016 at 02:33 AM 0
Share

Can you provide an example, with all digits, of the Y value you are seeing in Inspector and the Y value that's been 'changed'

1 Reply

· Add your reply
  • Sort: 
avatar image
3

Answer by leekenjen2328 · Jan 14, 2018 at 04:30 AM

,Hey, it has been a year since the question was asked, but just in case for anyone else: I was having the same problem. Basically for me I was using Character Controller with its own gravity defined, and also added a rigid body that has the gravity option ticked. So even if the character controller was not moving the game object, the rigid body was causing the y value to decrease. So deleting the rigid body from the game object and just leaving the character controller solved it for me. Hope this helps :)

Comment
Add comment · Show 1 · 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 TheRothius · Jul 13, 2021 at 06:29 PM 0
Share

This was my problem. Thank you so much.

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

11 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

Related Questions

Help with C# - destroy at a certain position not working 0 Answers

Any way to change transform.position of an indefinite number of gameobjects on FixedUpdate? 2 Answers

Distribute terrain in zones 3 Answers

Subtracting the position of transform from the position of Game Objects in a list. 1 Answer

Multiple Cars not working 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