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 /
  • Help Room /
avatar image
0
Question by OwnDemise · Apr 17, 2020 at 09:27 AM · moving platformframes

Unity Frame Rates and object movement

I'm curious about finding a better processing solution to this. I'm still in my early infancy of programming, and have been using unity for a few days now.

My question:

What is the most efficient way to buffer an object that moves based off a Time.time cycle.

I have an object which travels a fixed distance. It is then shifted on the y-axis by a preset amount.

The problem with this; there is an extremely small amount of time in which the object resets on path1, before being directed onto path2.

I've been able to account for this using co-routines...but when I get to to a tolerance of about 0.01s it's processing dependent and can sometimes fail.

Definitely over-complicating the explanation...so I hope someone smarter than me can point me in the right direction. Thanks in advance.

public class ScanSheet : MonoBehaviour { [SerializeField] Vector3 vectorMagnitude = new Vector3(0, 0, -1); [SerializeField] [Range(0.5f, 20f)] float period = 8.02f;

 enum State { Moving, FinishedMoving, GoToLine1, GoToLine2, GoToLine3 };
 State state = State.Moving;
 bool lineFinished = false;

 void Start()
 {

 }

 void Update()
 {
     //make a method that moves the MusicGuide from left to right
     ScanLeftRight();

 }



 public void ScanLeftRight()
 {
     // to movement bug at start of each line. Skips to starting position then down to next line.
     float timer;
     timer = Time.time % period;
     Vector3 line1 = new Vector3(6f, 9f, 4f);
     Vector3 line2 = new Vector3(6f, 7f, 4f);
     Vector3 line3 = new Vector3(6f, 5f, 4f);
     Vector3 finalPosition1 = new Vector3(6f, 9f, -4f);
     Vector3 finalPosition2 = new Vector3(6f, 7f, -4f);
     Vector3 finalPosition3 = new Vector3(6f, 5f, -4f);

     if (state == State.Moving || state == State.GoToLine1 && !lineFinished)
     {
         LineMovement(line1, finalPosition1, timer);
     }
     else if (state == State.GoToLine2 && lineFinished)
     {
         LineMovement(line2, finalPosition2, timer);
     }
     else if (state == State.GoToLine3 && !lineFinished)
     {
         LineMovement(line3, finalPosition3, timer);
     }
 }

 public void LineMovement(Vector3 a, Vector3 b, float t)
 {
     transform.position = a + vectorMagnitude * t;

     if (transform.position.z <= b.z)
     {
         StartCoroutine(BufferCoroutine());
     }
 }

 IEnumerator BufferCoroutine()
 {
     if (state == State.Moving || state == State.GoToLine1)
     {
         lineFinished = true;
         yield return new WaitForSeconds(0.105f);
         state = State.GoToLine2;
     }
     else if (state == State.GoToLine2)
     {
         yield return new WaitForSeconds(0.105f);
         state = State.GoToLine3;
         lineFinished = false;
     }
     else if (state == State.GoToLine3)
     {
         yield return new WaitForSeconds(0.105f);
         state = State.GoToLine1;
     }
 } }




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

196 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 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 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

Frame Base Jump Loop 0 Answers

Custom Rigidbody Controller and Moving Platforms 0 Answers

Coyote Timer Gives Double Jump Frames. 1 Answer

Mirror Networking Moving platform jittering 0 Answers

rigidbody2d on a moving stage 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