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 /
avatar image
3
Question by e-bonneville · Apr 07, 2010 at 02:58 PM · timemathframeratemotion

An Explanation of Multiplication (*) and how it relates to Time, deltaTime and framerate independent motion

Why do you use multiplication in scripting, and how does it work? For instance, if you want to change frame-rate to seconds or something, why would you use the * symbol? Like this:

var speed = 5;

function Update () { transform.Translate (0,0,speed * Time.time); }

From what I understand, that changes translate from frame-rate dependency to being time based, but how does it work? Is the * sign, not, like I think it is, actual multiplication, but a sort of 'translate' function?

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
9
Best Answer

Answer by duck · Apr 07, 2010 at 03:07 PM

No, it really is just basic multiplication. I have a feeling that in your example what you really meant to put is Time.deltaTime rather than Time.time.

This is because the value of Time.time increases linearly throughout the course of your playback - counting the seconds elapsed since the playback started, whereas Time.deltaTime gives you a value which is equal to the amount of time elapsed since the last frame.

If your game is running at a steady framerate, the value of Time.deltaTime will maintain a steady value, and it will only increase or decrease in value proportionally to the variations in the framerate that your game is achieving.

So, taking your example (but using deltaTime), and assuming the game is running at, say, around 60 frames per second, the value for deltaTime would be around 0.01666.

This means the object is moved a distance of ( 5 x 0.01666 ) units each frame, and if this happens 60 times a second, it will end up moving 5 units each second.

If the framerate dropped to 20 frames per second, the value of deltaTime would rise to 0.05 (because more time elapses between frames), and you'd end up with the object moving a distance of ( 5 x 0.05 ) units each frame, but because this is now happening only 20 times a second, it still ends up moving 5 units per second.

This is why multiplying your speed by the deltaTime value gives you framerate independent code.

Comment
Add comment · Show 6 · 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 Cyclops · Apr 07, 2010 at 03:10 PM 0
Share

Sigh, again @Duck beats me to the post :) Fortunately I checked before posting $$anonymous$$e. Good Answer, though. +1

avatar image e-bonneville · Apr 07, 2010 at 03:11 PM 0
Share

@Duck Oh, I see. Thanks a lot. What about other uses for *? Are they all really multiplication? I see it all over the place. For instance, when you use it in addForce. Noob question, I know, but there are just some things I need to know, no matter what the cost.

avatar image duck ♦♦ · Apr 07, 2010 at 03:13 PM 1
Share

Yes, with force it is just multiplication too, although often it's multiplying a Vector3, which means you are essentially altering the length of a vector.

avatar image e-bonneville · Apr 07, 2010 at 03:13 PM 0
Share

@Duck Thanks again... This logic is somewhat hard for me to grasp.

avatar image duck ♦♦ · Apr 07, 2010 at 03:17 PM 1
Share

The only time it gets particularly "hairy" is when it comes to multiplying rotations together - then it leaves the realm of normal multiplication and becomes something different. This is why, in the Quaternion documentation, there's a special page on the * operator describing its behaviour! :-) http://unity3d.com/support/documentation/ScriptReference/Quaternion-operator_multiply.html

Show more comments

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

No one has followed this question yet.

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Mathf.Repeat question... 1 Answer

A fast triangle triangle intersection algorithm for unity? 4 Answers

Calculations Wrong? 1 Answer

How to execute a function X times per second. 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