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 Bitcoon · Jun 05, 2014 at 07:33 AM · 2dvector2move speed

vector2.movetowards suddenly a lot faster

I'm kind of stumped as to why this just happened but I noticed today in my game that a lot of elements that do any translation motion are now moving probably 2x-3x faster than they used to a couple days ago. I haven't updated Unity and I don't remember changing any settings that would mess with that. Time still passes by at a normal rate (I don't mess with time scale changing at all) so I'm really stumped why all my hard-coded movement speeds seem to have suddenly become so faster.

By hard-coded I mean I just stuck in numbers that seemed right for speed instead of using variables. A lot of elements of my menus and other gameplay bits use 2d translation with Vector2.movetowards, but none of it effects gameplay, so it's not harming playability. It just looks a bit silly. I could just go through and change the numbers but I'm more curious why the heck everything suddenly just changed on me!

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

2 Replies

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

Answer by rutter · Jun 05, 2014 at 07:39 AM

One common pitfall:

 Vector2.MoveTowards(pos1, pos2, 1);

This moves up to 1 unit per frame. Which is fine... until your frame rate changes!

Instead of expressing movement in units-per-frame, you can express it in units-per-second:

 Vector2.MoveTowards(pos1, pos2, 10 * Time.deltaTime);

This moves up to 10 units per second. Time.deltaTime is the number of seconds since the last frame (usually a very small number). Multiplying your movement speed by the frame time gets you a constant movement rate per second, not per frame.

Bear in mind, deltaTime is very small (say, 0.03), so passing in small values may yield unintuitive results.

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 Bitcoon · Jun 05, 2014 at 07:36 PM 0
Share

Interesting... I haven't been using Time.deltaTime in those, but I also hadn't noticed any variability in the resulting rate of motion so I thought it was fine. I guess that's because Vsync was working correctly! (it's back to normal now so I guess somehow Vsync stopped properly limiting framerate back there for some reason...) I thought I was done making those sort of newbie mistakes, but I guess not. Thanks!

avatar image
2

Answer by JasonBricco · Jun 05, 2014 at 07:38 AM

You probably have frame rate dependent code, and the frame rate has changed. Consider multiplying your values by Time.deltaTime when it comes to movement.

To be more detailed on that: if you're saying move x units every single frame, then if your frame rate doubles, you're moving x units twice as fast as before, so you'll see a big speed up. Multiplying by Time.deltaTime makes it based on time instead of based on frame, so it will not matter where you run it.

Edit: fixed wrong wording.

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 Bitcoon · Jun 05, 2014 at 07:38 PM 0
Share

I guess it was Vsync that was keeping it consistent, then. Strange that it suddenly decided to stop (and started again today, now that it's back to normal without making any changes) but I'll definitely be changing that issue!

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

23 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

Related Questions

How do I rotate arround an object by swiping left or right? 0 Answers

How to use 2D pathfinding with vector 2 0 Answers

Assets/Scripts/PlayerController.cs(32,49): error CS0126: An object of a type convertible to `float' is required for the return statement 1 Answer

Hop from transform to transform in 2D game? 0 Answers

Why does my method "Vector2 SpawnPosition()" cause erratic behavior? 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