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 neilgoss · Apr 14, 2017 at 06:43 PM · vector3movetowards

Just cant get moveTowards vector3 to work.

Hi all,

I am trying to get an object to follow another as it randomly moves position. The problem is that the target (a cube) just blinks from position to position like it should, and the drone(a sphere) copies that behaviour, rather than actually travelling towards the target. i am using moveTowards method for this. here is the code, really appreciate any input on this one. Thanks in advance

 public float positionX = 0f;
 public float positionY = 0f;
 public float positionZ = 0f;

 private float  speed = 1f; // move speed


 public float delayTime = 0f;
 public float executeTime = 0f;



 private GameObject move_cube;
 private Vector3 wayPointPos;

 private GameObject drone;



 // Use this for initialization
 void Start () {
     executeTime = Random.Range (0f, 4f);
     move_cube = GameObject.Find("move_cube");
     drone = GameObject.Find ("drone");
 }
 

 void Update () {

     delayTime += Time.deltaTime;


     if (delayTime >= executeTime) {

         executeTime = Random.Range (0f, 4f);
         delayTime = 0f;
         positionX = Random.Range (0f, 5f);
         positionY = Random.Range (0f, 5f);
         positionZ = Random.Range (0f, 5f);
     }

     move_cube.transform.position = new Vector3 (positionX, positionY, positionZ);

     wayPointPos = new Vector3 (move_cube.transform.position.x, move_cube.transform.position.y, move_cube.transform.position.z);

     drone.transform.position = Vector3.MoveTowards(transform.position, wayPointPos, 1f * Time.deltaTime);


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
0

Answer by Cuttlas-U · Apr 14, 2017 at 07:22 PM

hi; use this :

 transform.Translate(Vector3.forward * MoveSpeed * Time.deltaTime);

this move your follower straight ahead so now u just need to make it look at your object to always follow it :

transform.LookAt(yourtarget);

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 neilgoss · Apr 14, 2017 at 10:29 PM

Hey Cuttlas-U

Thanks for that, it works great. Really appreciate it.

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

108 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

Related Questions

Vector3.MoveTowards Problems 0 Answers

How to create Curve between two points using **Vector3.MoveTowards**? 0 Answers

Vector3.MoveTowards 2 Answers

[Solved] Sliding garage door using transform.translate. 1 Answer

How to disable diagonal Vector3 movement of non-player object using MoveTowards? 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