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 ylama · Oct 15, 2013 at 11:21 AM · movementdelayfollowing

How can I make an object follow another's path with some time delay?

I need to make an object move exactly as another one, but with a delay of a few seconds. The "master" object's movements are not predictable. I have tried a lot of different approaches, such as using the Invoke and Sleep method, but nothing seems to have the desired effect. Help would be so much appreciated!

Comment
Add comment · Show 8
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 mattssonon · Oct 15, 2013 at 11:47 AM 0
Share

How is the master object moved? Can't you just save whatever variable is moving it and then apply it to the other object X seconds later?

avatar image ylama · Oct 15, 2013 at 11:51 AM 0
Share

The master object is moved by motion capture input using $$anonymous$$iddleVR. I have tried somehow saving the position variables in an array but I haven't found a way to make this approach work..

avatar image mattssonon · Oct 15, 2013 at 12:06 PM 0
Share

How about putting a script on the master object that sends its position to the following object when the master moves? The receiving object could then delay and execute every received position change?

avatar image ylama · Oct 15, 2013 at 12:12 PM 0
Share

Easier said than done. Since the master object is moving constantly, many not yet executed positions must be stored before being used my the slave object. I have tried writing them all in an array and having the slave object grab a position at the according time, but only got errors.

avatar image mattssonon · Oct 15, 2013 at 12:25 PM 0
Share

Have you tried just feeding it positions with a yield WaitForSeconds() statement in front?

Show more comments

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by mattssonon · Oct 15, 2013 at 12:33 PM

Which error are you getting? Are you coding in JS, because yield WaitForSeconds() is only valid in JS, in C# it would be yield return new WaitForSeconds(5);.

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 Statement · Oct 15, 2013 at 12:38 PM

There are at least two parts to the problems. One is storing the data and revisiting it for the "ghost" object. Another is dealing with prediction since just copying the position it had one frame may not give the smoothest experience if the game is not running at a solid frame rate.

Basically, you would keep an array large enough to store time and transformation position (time, position, rotation, scale, whatever you need?). If your game runs at 30 fps and you need 2 second delay, you need 30*2=60 elements in the array. If your game runs at 60 fps and you need 2 second delay, you need 60*2=120 elements in the array. You can also approximate by only recording position every x frames.

Each frame, record the timestamp and the positional data. Use an indexer variable that you keep incrementing that loops around to the start of the array once it hits the end of it. Something like this:

 data[i] = someData;
 i = (i + 1) % data.Length;

When it comes to reading the data, keep another indexer or time variable and find the two entries in your array between "last update" and "now", and get a new position by interpolating the "then" and "now" for the ghost. You can think of this as a circular array with two indexers chasing each other.

If you've thought about the problem for a bit, you'll also realise that your game might potentially run at variable frame rates. Figuring out a stable system may take some thinking to get it right.

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

16 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

Related Questions

GetKey have delay when relesed [SOLVED] 1 Answer

Button Press/Release delay on custom FPS character 0 Answers

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Camera Movement Smoothing 1 Answer

Making a bubble level (not a game but work tool) 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