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 verina09 · Sep 17, 2014 at 06:56 AM · movementvector3particlestimekeyframe

Plotting particle movement Time/keyframe issue

I have data with format as below:

 x               y             z            time T   
 -71.7087326    40.2462502    5.02939129    2.31992912
 -67.7142334    40.249218    5.09217882    5.15146351
 -61.1967964    40.2587852    5.23078823    9.7579298

I want to move a particle so that at time T, it will be at position x, y, z accordingly.

Currently what I do is to calculate average speed between 2 points (distance/time) and move the particle accordingly. Below is my code:

 class Data
 {
     Vector3 pos;
     float exactTime;
 }
 
 class CurrPoint
 {
     int id;
     float currTime;
     Vector3 avgSpeed;
 }
 
 CurrPoint p;
 Data data;
 
 void Update()
 {
     if(p.currTime == 0)
     {
         point.position = data[p.currID].pos;
     }
     
     p.currTime += Time.deltaTime;
     
     if (p.currTime < data[p.id].exactTime) 
     {
         point.position += Time.deltaTime * p.avgSpeed[p.id];
     } 
     else 
     {
         
         //exceeding value
         //not the last node
         if (p.id < data.Count - 1) 
         {
         
             //calculate time needed to complete to next pos
             float deltaT1 = data[p.id].exactTime - (p.currTime - Time.deltaTime);
             float deltaT2 = Time.deltaTime - deltaT1;
                 
                 
             //move to next id, calculate distance
             p.id++;
             points [i].position = data[p.id].pos;
             
             //move using new speed as much as deltaT2
             points [i].position += deltaT2 * p.avgSpeed [p.id];
         } 
         else 
         { 
             //last node
             //go back to beginning again (Reset)
             p.id = 0;
             p.currTime = 0;
         }
     }
 }

And here is what it is like when the game run: [http://youtu.be/1llmgJHNtPw]

As you can see, there are times when the particle will be 'pushed back' before moving again. I think it is because the time/framerate that is not right as I am using Time.deltaTime. The particle has travelled too far before processing data at next line.

How to ensure that this won't happen? Or perhaps if there is other suggestion, you are welcomed. Thanks a lot!

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

0 Replies

· Add your reply
  • Sort: 

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

2 People are following this question.

avatar image avatar image

Related Questions

Move from one position to another in x seconds 2 Answers

Object movement - undesired effects 1 Answer

Movement through an array over time 2 Answers

Move a keyframe in time only 1 Answer

Unexpected behavior on Vector3.moveTowards for Player 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