Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 /
  • Help Room /
avatar image
1
Question by Solid_Metal · Jun 06, 2016 at 12:04 PM · coordinates

gameobject.transform.position not working correctly

hey guys, so i try to move my object to certain coordinat, heres the code

 if (gameObject.transform.position.x <= -49.7f )
         {
             gameObject.transform.position = new Vector3(49.08f, 1f, 0.0f);
         }

 

while the object correctly move to the X coordinat i wanted, but not the Y coordinat, it always move to 0.404 on Y coordinat, it drives me mad, i already try everything but no avail, hope anyone can help

edit :

heres the complete script

 void Update ()
     {
         this.gameObject.transform.Translate(Vector3.left * platspeed * Time.deltaTime);
 
         if (gameObject.transform.position.x <= -49.7f )
         {
             gameObject.transform.position = new Vector3(49.08f, 1f, 0.0f);
         }
   }

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 Hellium · Jun 06, 2016 at 11:24 AM 0
Share

gameobject.transform.position not working correctly

No, YOU do something wrong. Stop bla$$anonymous$$g Unity.

Provide your whole script please. You surely move the object somewhere else

avatar image Solid_Metal Hellium · Jun 06, 2016 at 12:08 PM 0
Share

i add the full script with the update function

avatar image Side · Jun 06, 2016 at 12:48 PM -1
Share

Try

  transform.x -= platspeed * Time.deltaTime;

ins$$anonymous$$d of

  this.gameObject.transform.Translate(Vector3.left * platspeed * Time.deltaTime);

and tell me if it works.

avatar image Hellium Side · Jun 06, 2016 at 12:58 PM 0
Share
  transform.x -= platspeed * Time.deltaTime;

  1. Transform has not any property / attribute called x

  2. If you meant transform.position.x, you can't directly modify one component of the direction vector

avatar image Hellium · Jun 06, 2016 at 01:00 PM 0
Share

As the documentation says :

If relativeTo is left out or set to Space.Self the movement is applied relative to the transform's local axes.

Are you sure the rotation of your object is (0,0,0) ? If not, try

  transform.Translate(Vector3.left * platspeed * Time.deltaTime, Space.World);
avatar image Solid_Metal Hellium · Jun 07, 2016 at 04:56 AM 0
Share

still not avail

the problem is not on the translate, but on this code :

 gameObject.transform.position = new Vector3(49.08f, 1f, 0.0f);

everytime it execute that script, the Y always on 1.404 not fix 1, but the X work correctly

avatar image Hellium Solid_Metal · Jun 07, 2016 at 07:27 AM 1
Share

Have you tried to disable this script and see if another script moves your object ?

Show more comments
avatar image zedsmith52 · May 10, 2017 at 04:35 PM 0
Share

I am having the same issue with a similar piece of code.

In fact, if I do the following:

 gameObject.transform.position = new Vector3 (0.0f, 0.0f, 0.0f);

The object moves!! (even though the object started at (0,0,0).

Can anyone help?

avatar image ThatIntermediateAj · Apr 11, 2020 at 01:58 PM 0
Share

Have you tried using void LateUpdate() ins$$anonymous$$d of void Update() ? Other scripts may have been setting their own values for the transform(i.e. Character controller, Nav$$anonymous$$eshAgent).

3 Replies

· Add your reply
  • Sort: 
avatar image
7

Answer by brett_henning · Aug 17, 2017 at 08:32 AM

Is it the child of another Game Object? Could try gameObject.transform.localPosition

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 TheBleedingNova · Oct 07, 2017 at 07:14 AM 0
Share

This was the issue for me. You are a life saver.

avatar image Lukalotr · Oct 18, 2018 at 03:43 PM 0
Share

Fantastic! Fixed my issue!

avatar image
1

Answer by zedsmith52 · May 10, 2017 at 04:55 PM

I am having the same issue with a similar piece of code.

In fact, if I do the following:

 gameObject.transform.position = new Vector3 (0.0f, 0.0f, 0.0f);

The object moves!! (even though the object started at (0,0,0).

Can anyone help?

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
avatar image
0

Answer by spospider · Aug 21, 2019 at 02:15 PM

For anyone having this issue try using "transform.TransformPoint(Vector3.zero)" instead of using "transform.position". It returns the object's position in world space(as"transform.position" should do). This saved me after days of trial and error.

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

66 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 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 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

Getting an object's y coordinate 2 Answers

Converting screen space to rectTransform space 0 Answers

Getting position of a coordinate on the surface of a sphere 0 Answers

Get colour of a pixel on a texture? 2 Answers

GPS coordinates not changing at all! 0 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