Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 Keavon · Apr 03, 2011 at 09:54 PM · 3dobjectmovefollowtrack

Make Object Move to/follow Another Object? (plus turn towards it)

Hello.
I am trying to make a simple game where objects close in on an other object (you!).
I am having them spawn all around the character in a random location, so I will not be able to know where they are.
What I want to be able to do is have a script that will have a speed variable controlling how fast they come towards you.
I suck at scripting though, and I am even worse at scripting the movement of objects in 3D space.
I would also like the script to be compatible with following a character that moves. I was hoping some nice scripting guru could give me a script or lead me in the right path.
I saw something once a long time ago, a very complex Youtube tutorial, to doing what I want, but I can't find it plus it was in C# which I am trying to avoid, as I use Javascript.
I would really appreciate some help!
:P
Thanks!!

EDIT: I just remembered that the script will also need to have the object turn so it is always facing towards you. The objects are pieces of text, and I can't see some of them because they are either reversed or I am seeing the side.

2nd EDIT:
Thank you for your responce. Now I need a second script that will turn it forward facing the target. Anyone?
Thanks!

Comment
Add comment · Show 2
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 Bubinga_Studios · Nov 04, 2016 at 07:10 PM 0
Share

I can't seem to find out how to make the target. Could someone please get back to me?

avatar image aqrayousef · Sep 09, 2017 at 12:19 PM 0
Share

could u please give me the link or the youtube tutorial ...?

2 Replies

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

Answer by Kobby · Apr 03, 2011 at 10:57 PM

Look in to the Vector3.moveTowards() function. it takes a current position, a target position and a float to determine the rate at which your object moves.

function Update(){
    transform.position = Vector3.MoveTowards(transform.position, targ.transform.position, .03);
}

Also Lerping could do it for you

function Update () {
    transform.position = Vector3.Lerp(start.position, end.position, Time.time);
}

Comment
Add comment · Show 6 · 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 Keavon · Apr 04, 2011 at 03:30 AM 0
Share

Hi. Thank you for your answer. The problem is that this script does not turn the gameobject to face forward towards the specified target. Any ideas on a second script to do that? Thanks!

avatar image Kobby · Apr 04, 2011 at 02:38 PM 0
Share

sorry I forgot to respond to the edit. you can also call a transform.lookAt() that will keep your objects looking at 1 game object all the time.

private var targ: GameObject;

function Update(){ transform.LookAt(targ.transform); }

avatar image Kobby · Apr 04, 2011 at 02:38 PM 0
Share

sorry for the unformatted code

avatar image vverma9 · Jan 29, 2017 at 12:23 AM 0
Share

I amble to do the target follow thing. However, there are a number of other collider objects in between the target and the follower, and my follower(which has a collider component) is moving through those objects. How do I make him move around those objects ins$$anonymous$$d of through them?

avatar image xKittenCatx · Jul 01, 2021 at 12:25 AM 0
Share

Thank-you! You're the best! It worked perfectly for me. I multiplied my float speed by Time.deltaTime for a smoother performance.

Show more comments
avatar image
0

Answer by dragen000 · Sep 18, 2015 at 12:36 PM

I have some thing similar i'm working on but i C# could you take a look at it. it doesn't seem to work. using UnityEngine; using System.Collections;

 public class FollowAI : MonoBehaviour {
 
     public GameObject target; //the enemy's target
     public float moveSpeed = 5; //move speed
     public float rotationSpeed = 5; //speed of turning
     private Rigidbody rb;
     private Vector3 mytransform = target;
 
     void Start()
     {
         rb = GetComponent<Rigidbody>();
     }
 
 
    void Update()
     {
         //rotate to look at the player
         transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(target.position - transform.position), rotationSpeed * Time.deltaTime);
 
 
         //move towards the player
         transform.position += transform.forward * Time.deltaTime * moveSpeed;
 
     }
 
 }
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 vverma9 · Jan 29, 2017 at 12:23 AM 0
Share

I amble to do the target follow thing. However, there are a number of other collider objects in between the target and the follower, and my follower(which has a collider component) is moving through those objects. How do I make him move around those objects ins$$anonymous$$d of through them?

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

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

object follow mouse position in 3d world. 1 Answer

How to follow a moving object by camera on a line ? 1 Answer

Object where the mouse is 4 Answers

How to make a follow AI 4 Answers

Objects without Textures... 3 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