Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 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 magical · Mar 07, 2013 at 01:39 PM · timerecording

Dynamic recording of objects position seems fine, playback is too fast.

Im new to unity and im wanting to record the movement of an object so that it can be played back. I have the x,y,z positions recorded but when it comes to replaying the movement it is happening so fast that it gives the impression that the gameobject jumps to the last recorded position instead of actually moving through the recorded positions.

Im stuck as to how i can replay the movement at the same speed as it happened.

my code for this is:

 using UnityEngine;
 using System;
 using System.Collections;
 using System.Collections.Generic;
 
 public class recordv1 : MonoBehaviour {
 
     List<float> nums = new List<float>();
     bool isRec = false;
     bool doPlay = false;
     float tempX;
     float tempY;
     float tempZ;
     // Use this for initialization
     void Start () {
     
     }
     
     // Update is called once per frame
     void Update () {
     
         if( Input.GetKeyDown (KeyCode.R)) {
             if( isRec == false){isRec = true;}
             else{
                 if( isRec == true){isRec = false;}
                 
             }
         }
         
         if( isRec == true){
             tempX = transform.position.x;
             tempY = transform.position.y;
             tempZ = transform.position.z;
             nums.Add(tempX);
             nums.Add(tempY);
             nums.Add(tempZ);
         }
         
         if( Input.GetKeyDown (KeyCode.P)) {
             if( doPlay == false){doPlay = true;}
             else{}
             
         if(doPlay == true){
             
             for (int i = 0; i < nums.Count; i+=3){
                     transform.position = new Vector3(nums[i],nums[i+1],nums[i+2]);
                     
                 }
                 doPlay = false;
                 
             }
         }
         
         
     }
 }
 
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 Statement · Mar 07, 2013 at 04:50 PM

Yeah, you should only update the position once a frame. Not all of them in one frame. I can see two obvious ways you could do it. One is to declare the variable "i" that you use to become a member variable so it remembers where it is between calls. You'd have to make special check to see if you reached the end before you set doPlay to false.

The other is to use a coroutine that processes them each frame. You can wait for the next frame with "yield return null;".

 IEnumerator Playback ()
 {
     for (int i = 0; i < nums.Count; i+=3) {
         transform.position = new Vector3 (nums [i], nums [i + 1], nums [i + 2]);
         yield return null;
     }
 }

To start it, you should call StartCoroutine("Playback");

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 magical · Mar 07, 2013 at 07:54 PM 0
Share

Thanks that makes sense. Although wouldnt this then change the speed the movement is 'played' depending on the computer i.e. one computer may run the game at 30fps while another could be 60fps which would play the movement at double the speed. Or have i misunderstood something.

avatar image alexis78963_unity · Apr 29, 2021 at 03:11 PM 0
Share

It's very late but if anyone needs to do this again, you should record the positions in FixedUpdate to not have strange behaviors if some frames drop. Then the coroutine should be:

 yield return new WaitForFixedUpdate();

So that the playback and recording ti$$anonymous$$g matches

avatar image
0

Answer by omarcesar · Feb 05, 2016 at 02:40 AM

this plug-in helps record movement of any 3d object, including avatars or complex object with multiple children.. all you do is check one flag. Easy to import and use. check out the demo: https://www.youtube.com/watch?v=Ay-wuj5PvHU

link in asset store; https://www.assetstore.unity3d.com/en/#!/content/17836

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

13 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

Related Questions

Complex Mecanim recording in a single game update? 1 Answer

How to create a system to go back in time as in Prince of Persia? 3 Answers

"Slowing time" in area 1 Answer

how to decrease repeating time in invokerepeating? 2 Answers

How to end an animator animation using time? 0 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