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 Qasem2014 · Apr 09, 2015 at 02:04 PM · positiongoto

Vector3.MoveTowards help :(

hi . i have a code like this and its very good :

 var GO:GameObject; var GO2:Transform;
 function Update()
 {
    GO.transform.position=Vector3.MoveTowards(GO.transform.position,GO2.position,Time.deltaTime*2);
 }

But i wana make GO game object don't change in Y position . i wana GO game object just move for reach X and Z of GO2 !

excuse me for my bad english :) if have question , just ask :D

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 Pharaoh_ · Apr 09, 2015 at 02:13 PM

In the Start() method, set InitY = GO.transform.position.y; In the Update() method,

 Vector3 newVec = new Vector3 (GO.transform.position.x, InitY, GO.transform.position.z);
 GO.transform.position=Vector3.MoveTowards(newVec,GO2.transform.position,Time.deltaTime*2);
Comment
Add comment · Show 4 · 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 Qasem2014 · Apr 09, 2015 at 03:12 PM 0
Share

TNX :)

avatar image Qasem2014 · Apr 09, 2015 at 03:20 PM 0
Share

BUT a pronlem come up :(

when i use your code the GO.transform.position.x/z never equal with GO2.transform.position.x/z !!!!!

STRANGE !

numbers is like this : GO.transform.position.x = 0.09 and GO2.transform.position.x = 0.1 !!!! they never reach together !

but with my code they are equal , like this : GO.transform.position.x = 0.1 and GO2.transform.position.x = 0.1

avatar image Bonfire-Boy · Apr 09, 2015 at 04:45 PM 0
Share

I may be misunderstanding the question but that looks wrong to me. It can change the y coordinate of GO (because it's moved towards GO2's position). You want to move GO towards a point that has its y coordinate but GO2's x and z. So something like..

 Vector3 newVec = GO2.position;
 newVec.y = GO.transform.position.y;
 GO.transform.position = Vector3.$$anonymous$$oveTowards( GO.transform.position, newVec, speed);
 
avatar image Qasem2014 · Apr 09, 2015 at 06:24 PM 0
Share

Thank You So $$anonymous$$uch BonFire-Boy . i close this question but i vote your answers up 3 time :) :D you solve it :)

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

19 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

Related Questions

Camera rotation around player while following. 6 Answers

Freeze rigidbody position without affecting rotation - please help! 1 Answer

making position checker - is area empty or not (with trigger)? 2 Answers

How to change animation in the code? 1 Answer

players positions when race ends. 4 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