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 madruytb · Nov 24, 2019 at 09:45 PM · 2dvector

Game Objects same transform.position value, sitting on different places

So in my game, I have a bunch of parent gameobjects which I'm trying to move via script, they are instantiated and start moving to their final position which is x: 0 y: -6. The issue is, every parent object which is being moved goes to a different place when I set their transform to y: -6. I added a screenshot so it gets clearer. alt text

I'm not an expert but I believe that this is caused because these gameobjects have children, so it changes their transform positions in a way I can't understand, is there any way that I can access a "global" position and move the gameobjects towards it? My current script responsible for moving the bricks:

 public class MoveBrickSc : MonoBehaviour
 {
 
     WavesScript waveSc;
     GameObject finalPosObj;
     Vector3 finalPos;
     float speed;
 
 
 
     // Start is called before the first frame update
     void Start()
     {
         waveSc = GameObject.FindObjectOfType<WavesScript>();
 
         finalPosObj = GameObject.Find("FinalPos");
 
         finalPos = finalPosObj.gameObject.transform.position;
         speed = waveSc.moveSpeed;
         
     }
 
     // Update is called once per frame
     void Update()
     {
         transform.position = Vector3.MoveTowards (transform.position, finalPos, speed * Time.deltaTime);
     }
 }

xclr.png (117.4 kB)
Comment
Add comment · Show 1
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 myzzie · Nov 24, 2019 at 11:46 PM 0
Share

Could you clarify what's going wrong? You're moving transform.position towards finalPos, it's not possible for your transform to get a different end position unless it's a child object, in which case it'd show local coordinates. I'm unable to replicate your result.

2 Replies

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

Answer by Bunny83 · Nov 25, 2019 at 12:21 AM

We don't see your gizmo editor setting. Make sure you have it set to "pivot" and not to "center". Keep in mind that the position of your gameobject is always relative to the pivot.


Also note that you grab the position of your "FinalPos" gameobject in Start. If the position changes afterwards it won't affect your position stored in the variable "finalPos".


We can't really say much more about your issue since a lot details are missing which only you can check in your project.

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 madruytb · Nov 25, 2019 at 02:56 AM 0
Share

Sorry, I'm not sure where to check the gizmo editor setting you said. And I dont think that grabbing the position in Start should be a problem since FinalPos gameobject never moves during the game/ after Start() .

avatar image Bunny83 madruytb · Nov 25, 2019 at 03:35 AM 0
Share

I'm talking about this one:

See this documentation page for additional reference

avatar image
0

Answer by aminbenslimen00 · Nov 24, 2019 at 10:02 PM

use transform.localposition instead of transform.positon

let me know if that fix it

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 madruytb · Nov 24, 2019 at 11:26 PM 1
Share

Transform.localPosition: "Description Position of the transform relative to the parent transform.

If the transform has no parent, it is the same as Transform.position."

I dont think that would work since I'm moving the parent object and not child.

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

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

How do I make one object go in the same way and with the same speed as the other object? 1 Answer

Getting a 2d Sprite to move over time to an Array 1 Answer

Basic 2D movement C# - Key presses cancel eachother out 4 Answers

Assets/Scripts/PlayerController.cs(32,49): error CS0126: An object of a type convertible to `float' is required for the return statement 1 Answer

On which side of the object is this point - 2D 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