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 DevMerlin · Feb 17, 2013 at 11:35 PM · gameobjecttranslatedamping

How can a gameobject follow the last gameobject in a chain?

I'm trying to get a gameobject to follow another gameobject, without being parented so the following object can get lost, and separated from the primary gameobject. I had a very rough follow without damping, and it never looked very good. I'd like to improve and fix that. My goal is to get multiple gameobjects following eachother in a loose chain.

 moveForward = transform.forward * basicSpeed * Time.deltaTime;
     
 Quaternion rotationChange = Quaternion.LookRotation(followPos - transform.position);
 transform.rotation = Quaternion.Slerp(transform.rotation, rotationChange, 6f * Time.deltaTime);
 transform.Translate(moveForward);
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 froYo · Feb 18, 2013 at 12:06 AM

This should give you the results you're looking for it's in UnityScript so I hope that's ok:

 var follow : GameObject;
 var xOffset : int;
 var yOffset : int;
 var zOffset : int;
 
 function FixedUpdate () 
 {
     transform.position = Vector3(Mathf.Lerp(transform.position.x, follow.transform.position.x + xOffset, Time.deltaTime),Mathf.Lerp(transform.position.y, follow.transform.position.y + yOffset, Time.deltaTime),Mathf.Lerp(transform.position.z, follow.transform.position.z + zOffset, Time.deltaTime));
 }

Just add the script onto all of the following objects and drag and drop the object it should follow into the follow variable.

Then you can change the offset so that the object stays a certain distance behind the object it's following.

Hope this helps :)

Edited to fixedupdate

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 froYo · Feb 18, 2013 at 12:09 AM 0
Share

Although it does give a kind of elastic effect, not sure if you want that or not

avatar image DevMerlin · Feb 18, 2013 at 12:21 AM 0
Share

UnityScript is fine - Converting to C# is fairly simple. Elastic should be fine too, it's an arcade game so physics don't come into play. :)

avatar image
0

Answer by digiben · Feb 17, 2013 at 11:38 PM

Can you just decrease the basicSpeed to be slower for the following object? You can use iTween to set a speed as well and follow them, but just set the speed to a realistic speed that the object being chased can outrun.

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 DevMerlin · Feb 17, 2013 at 11:43 PM 0
Share

No, because there are multiple objects in the chain. Each gameobject follows the last one in the chain.

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

11 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

Related Questions

How to make an object go to pre-seted position in world 1 Answer

How to move an object to anothers object position? 1 Answer

Need help for Translating a peg in the game... 1 Answer

How do you make bullets face the direction it's going? 0 Answers

How to make this kind of control ? 2 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