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 /
  • Help Room /
avatar image
0
Question by Panchos · Jan 29, 2016 at 01:10 PM · movementgameobjectvector3.movetowards

Stopping a MoveTowards

I'm using Vector3.MoveTowards to move a gameobject from A to B.

When the user pauses the game though, I want the gameobject to stop moving.

How can I force the moving gameobject to stop if pause == true ?

Comment
Add comment · Show 4
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 Wolfdog · Jan 29, 2016 at 02:54 PM 0
Share

Posting your code containing the function would help people answer your question.

avatar image Panchos Wolfdog · Jan 29, 2016 at 03:52 PM 0
Share

The code is just 'transform.position = Vector3.$$anonymous$$oveTowards (transform.position, target.position, 1)'. That moves it, I just don't know how to force it to stop before it reaches end

avatar image Dave-Carlile · Jan 29, 2016 at 04:01 PM 0
Share

Just stop calling it.

 if (!pause)
 {
     // do stuff when you're not paused
 }
avatar image Panchos Dave-Carlile · Jan 29, 2016 at 04:11 PM 0
Share

ahh, I got confused. I thought when you call the code it moves to that location until it reaches it, didn't realize it had to be done each loop. Thanks

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by ThomasVandenberghe · Jan 29, 2016 at 04:00 PM

 if (!paused)
 {
     transform.position = Vector3.MoveTowards (transform.position, target.position, 1);
 }

Now only when the game is not paused the code will be executed.

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 $$anonymous$$ · Jan 31, 2016 at 02:46 PM

you might want to use this bit of code

 Time.timeScale = 0;
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 ata_2 · Jan 31, 2016 at 02:47 PM

i think simple way to do it is to when you try to pause game use this code Time.timeScale = 0f; and when want to resume game use this code Time.timeScale = 1f; try this if you get any problem with this you can put your code in one if to check if pause menu showed like active don't run this code

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

42 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

Related Questions

GameObject not looking at me.. 1 Answer

Player Only Moves When I Touch The GameObject Directly But I Want To Touch And Move From Anywhere From The Screen,Player Moves By Touch but ONLY When I Touch The GameObject. 0 Answers

How to restrict object's movement to a bezier curve? 0 Answers

How can I stop a gameobject movement with timer? 0 Answers

Mesh Movement 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