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 Guardian2300 · Mar 12, 2013 at 05:17 AM · movementarraysspeedgameobjects

Moving Gameobject and Reseting Issues

Been having trouble where I have the tiles moving in one direction and after it hits a certain point I would like it to reset the position back to 0 and have the movement keep going. Also with this I would like to change the movement speed of the object when needed. I keep coming across the issue of gameobjects creates a huge gap after they gets reseted to 0

Here's an example. alt text

So if I keep the speed at around 0.1 or 1 it should be fine but if I would like to increase it it always gives me the unwanted spacing. Note that there are 100 gameobjects running the same script.

My Sample Script is #pragma strict

 function Start () 
 {
 
 }
 
 function Update () 
 {
     Move();
 }
 function Move()
 {
     var speed : float = 0.03;
     transform.position.z = transform.position.z + speed;
     
     if(transform.position.z >= 20)
     {
         transform.position.z = 0;
     }
     
     
 }

So I was wondering, what are your suggestion of solving this issue?

spacing.png (9.5 kB)
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

3 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by robertbu · Mar 12, 2013 at 05:48 AM

Whatever speed you are selecting, the chance the last tile will exactly reach 20 is remote. Most of the time it will lap over the 20.0 limit. That means that all rows of tiles behind the front row will be a bit ahead as well, so when you move the tile back to the beginning, there will be a gap between the new rear tiles and the row just in front of them. One solution is to account for the overlap, but placing it forward of 0.0 by the amount of the overlap. In addition, the code should really scale by Time.deltaTime:

 function Move()
 {
     var speed : float = 1.0;
     transform.position.z = transform.position.z + speed * Time.deltaTime;
  
     if(transform.position.z >= 20)
     {
        transform.position.z = transform.position.z - 20.0;
     }
 }

There may still be roundoff errors that cause an opening. I'm not sure without testing, but the situation should be much improved.

Comment
Add comment · Show 1 · 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 Guardian2300 · Apr 17, 2013 at 07:06 AM 0
Share

Your method seems to work the best out of them so thank you and all for trying. I also tried when transform.position.z = 0 - difference; difference is distance away from max distance when it got reseted. When You run the program faster it seems jittery, have to build it to make it look clean.

avatar image
0

Answer by 3dws · Mar 12, 2013 at 05:43 AM

maybe u must sync it with your fps . check this :

 transform.position.z = transform.position.z + speed*Time.deltaTime;
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 Seth-Bergman · Mar 12, 2013 at 06:03 AM

The problem with your logic is due to the scale of your movement.. if you set speed to "1", the object is moving 1 world unit forward EACH FRAME.

lets say the object is 3 and a half units long.. since it is moving in 1-unit increments, the next guy in front cannot be 3 1/2 units ahead, it must be 4, which leaves a gap of 1/2 a unit.. increasing the speed increases the degree of inaccuracy!

to fix, you need to add logic to fill the gap somehow.. the trick is to make sure that the speed is always precisely divisible by the objects length..

   var speedIncrement = renderer.bounds.extents / 100;

   if(whatever)
   speed += speedIncrement;

(for example)

you shouldn't really need to use bounds.extents.. just make sure the increment goes exactly into the desired length..

come to think of it, the target distance (instead of 20) may also need to be a multiple of said length in this scenario... or you will need to account for that difference..

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

12 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

Related Questions

objects in the same array wont move 0 Answers

Moving up and down (in a slope) without change to velocity or "bumping" 0 Answers

Problem in placing my array pieces 3 Answers

How do I make a Game Object move when I collide it ingame. 2 Answers

Wheel rotation help cant work out the problem? 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