• 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 Xeong-Hu · Feb 05, 2015 at 06:02 PM · movetowards

How do i make my object move towards an object but not exactly at the desginated location.

Well. Here's what I mean.

Y'know how when a character would follow a character but not exactly stop at the followed charcters exact position?

Hmm, well kind of like Sonic and Tails.

I'm getting a hunch that I need to use the Movetowards function but then add additional numbers around it such as Movetowards this object X Position plus 3

I'm thinking something like that. I'd appreciate it if someone gave me a hand.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Chris333 · Feb 05, 2015 at 06:21 PM

Hi,

check the vector of the object you want to move and the vector of the target object. Than stop the movement when the vector from MovingObject to targetObject have a specific length.

e.g.:

 direction = tails.transform.position - sonic.transform.position;
 if(direction.magnitude < distance)
 {
     //stop moving
 }

Assuming that tails follows sonic.

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 Xeong-Hu · Feb 05, 2015 at 07:41 PM 0
Share

Hmm.. Well ok I'll use this.

But sadly I'm starting to think I asked the wrong question..

Hmm.. i'll just try and see..

avatar image Chris333 · Feb 05, 2015 at 08:16 PM 0
Share

Do you want to have a fixed position where the follower always stops?

avatar image
1

Answer by KazooCar69 · Feb 05, 2015 at 06:23 PM

First you want to figure out what your stopping distance is. There's a few ways to do this - you could put a debug.log(Vector3.distance(character1.transform.position, character2.transform.position) and position your characters in play mode until they're at a distance you like. Or trial and error it.

Once you have that number (or again, make it up and adjust as needed) you can certainly use MoveTowards if that makes sense for you. You can then do something like

 if(Vector3.Distance(character1.transform,position, character2.transform.position) > stoppingDistance)
 {
     //Movement stuff here
 }

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

21 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

Related Questions

MoveTowards not moving towards! lol. 1 Answer

Help with moving AI object to nearest spawned objects position 0 Answers

Make object jump to fixed y position 1 Answer

How can I move an object to a (0,0) and scale it to (0,0) at the same time? 1 Answer

MoveTowards not working well with Rigidbody jumping mechanics 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