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 /
avatar image
0
Question by parkmaster15 · Jun 05, 2018 at 04:48 AM · object follow path

How to make an object follow another object in a certain way

So I'm using the unity rollerball prefab and want an object to follow right behind it no matter which way it goes. For example: if the ball is going north/up, the object would be behind/ down, relative to the ball. If I'm going up and left the object would be down and right in comparison to the ball. I tried using,

public Vector3 offset; public Rigidbody player; public float distance; public GameObject trigger;

 void Update () {

     offset = -player.velocity * distance;
     trigger.transform.position = player.transform.position + offset;
     

 }

This gets the right effect, but because it is based on velocity, the faster the ball goes the farther the object lags behind. Also if the object stops moving then the object just appears inside the ball because the velocity is 0. Any suggestions how I could make this work? Anything is appreciated. I guess i'm trying to make a game similar to the Mario party game where you try to pop the balloon on the back of a go-kart where the balloon is always behind the kart.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by MuffinMan64 · Jun 05, 2018 at 05:24 AM

@parkmaster15 I would have a desired goto position that would be located in the back of the ball. This could be either an empty gameObject or a gameObject that has a rigidbody without gravity and with kinematic set to true. You may need to play with the freeze x,y, and/or z constraints, if the ball actually rolls (you don't want your desired position to roll too!).

Lets call the desired object that follows the ball, ball_follower as a gameObject. Lets call the ball object, ball as a gameObject. Lets call the desired location, goto_spot as a child gameObject of ball. Lets assume that the following script is on ball.

If you want only one object to be behind the ball from the start:

    void Start()
     {
     transform.parent = goto_spot.transform;
     }


If you want only one object to be behind the ball and gradually go to the desired location:

  float speed = 1f;
         void Update()
         {
              transform.position = Vector3.MoveTowards(transform.position, goto_spot.transform.position, speed);
         
         }

Try it and let me know!

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

82 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

Related Questions

Partner follow the player 0 Answers

Instantiating Texture2D Object get non-readable error about AssetBundle 3 Answers

How to use individual Particles as objects 1 Answer

Get ClosestPointOnBounds when inside bounds? 2 Answers

How to create a Path 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