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 Hexer · May 24, 2015 at 11:41 PM · c#mathtime.deltatimeexponential

Increase the speed but keep the spacing between the objects

I have been wondering something when I was playing around with an old script of mine

 public float movespeed;
     private Vector3 Direction;
 
     void Start(){
         movespeed = 4f;
         Direction = Vector3.right;
     }
 
     // Update is called once per frame
     void Update () {
         transform.Translate (Direction * movespeed * Time.deltaTime);
 

This script lets an object, were it is attached to, move automatically to the right with a given speed. This script is attached to 1 object that gets instantiated every 1float by using the InvokeRepeat method. I was wondering why the spacing between 2 instantiated objects are greater when you increase the movespeed, as example from 4f to 5f.

I saw that if you increase the amount the function would be called that the spacing between the two objects would be smaller. Knowing this I used an exponential growth formula. Looking for 2 points were the spacing between objects are 4x.

Formula -> Float = B*A^t

Movespeed 4 equals a "t" of zero, 0. (movespeed 5 equals "t" of 1, movespeed 6 equals "t" of 2, etc.)

at movespeed 4 a float of 1 was given

at movespeed 10 a float of 0.4 was given

(0.4/1)^1/6 = A

0.4/A^6 = B

But even this won't give me a correct float for every movespeed. Even when calculating with 9 numbers behind the decimals. The spacing between the objects is off by [0.1x - 0.3x]

I was wondering if there is another method to increase the speed but keeping the spacing between the objects the same.

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

1 Reply

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

Answer by Bunny83 · May 24, 2015 at 11:58 PM

Uhm, isn't that obvious o.O?

If your object moves 4 units per second and you instantiate a new object at the same starting point every second, the space between them is 4 units as the first object has moved 4 units in one second...

If you change the speed to 5 units per second the spacing is of course 5 units.

I'm not sure how you come to the conclusion that any kind of exponential growth happens here...

edit

So you actually want to calculate at which interval you have to instantiate your objects to have them spaced with a given distance.

That's quite easy:

 float CalulateInterval(float aSpeed, float aSpacing)
 {
     return aSpacing / aSpeed;
 }

By using this method you simply pass your speed and your desired spacing between the objects and it returns the interval in seconds.

Some examples:

 Speed  spacing  interval
 ------------------------
 4      4        1
 5      4        0.8
 10     4        0.4
 4      2        0.5
Comment
Add comment · Show 5 · 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 Hexer · May 25, 2015 at 12:05 AM 0
Share

Oh, yeah I thought I could calculate the exactly float needed in the InvokeRepeat method to get a spacing of 4x everytime. that is what I meant. And it kinda works but as I said with a differential of [0.1x - 0.3x]

But yes your comment sounds logical. thx

avatar image Bunny83 · May 25, 2015 at 12:10 AM 0
Share

Uhm, your question was "why is that" and not "How can i make the spacing stays the same even when i increase the speed"...

If you ask a question make sure you actually know what you want to ask. It's usually the best to write the title after you finished with the description of your problem...

I'll edit my answer...

avatar image Hexer · May 25, 2015 at 12:13 AM 0
Share

You can say I put 2 questions in my post. (Title changed)

EDIT Sigh.. yes thanks for opening my eyes, my brain just derped really badly. I wonder how I did not saw that earlier. (Smashing head against table..)

avatar image Bunny83 · May 25, 2015 at 12:29 AM 0
Share

btw: If you transfer this to real world units, just look at the unit equations:

spacing in meters ( m )
speed in meters per second ( m/s )
interval in seconds ( s )

 spacing   /   speed   ==  interval
    m      /    m/s    ==     s

If you would reverse spacing and speed you would get the frequency in Hz:

 freq   ==   speed   /  spacing
  1/s   ==    m/s    /     m

So the frequency tells you how many objects you have to create in one second while the interval tells you how many second you have to wait between each instantiation.

avatar image Hexer · May 25, 2015 at 12:32 AM 0
Share

Yes, I have studied $$anonymous$$ath in University ._. I am not dumb xD..

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

20 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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Player rapidly accelerating instead of stopping 1 Answer

Projectile motion arc 2d 1 Answer

Math exponential number conversion 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