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 hamcola · Feb 17, 2015 at 10:45 AM · performancespeedspeed issues

Objects moving slowly in preview.

I have a project with 5 scenes. (2d platformer side-scroller game)

In each scene, there are objects that move (controlled by a movement script). The speed at which they move is static. Nothing in my environment has changed over the course of game development.

Now for some reason, during preview, my objects move much much slower than before (SO SLOW) it's hard to 'test' my game so to speak. Only objects with a movement script attached (I have a few different movement scripts) are affected by this slow-down (these are things like moving platforms, enemies, props etc).

When I execute the game as a desktop app, objects move at the correct/normal movement speed.

What could be causing this slow-down in preview? Anyone have a clue? I would be happy to provide more detail.

Comment
Add comment · Show 3
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 sniper43 · Feb 17, 2015 at 11:08 AM 0
Share

What are you using to move?

Some code would be nice.

avatar image hamcola · Feb 17, 2015 at 05:50 PM 0
Share
 private var Xpos : float;
 private var Ypos : float;
 private var max : boolean;
 
 var Vert : boolean;
 var maxAmount : int;
 var step : float;
 
 
 function Start () {
 
     Xpos = transform.position.x;
     Ypos = transform.position.y;
 
 }
 
 function Update () {
     //set the max
     if(Vert) { //verticle
         if(transform.position.y >= Ypos + maxAmount){
             max = true;
         } else if(transform.position.y <= Ypos){
             max = false;
         }
     } else { //horizontal
         if(transform.position.x >= Xpos + maxAmount){
             max = true;
         } else if(transform.position.x <= Xpos){
             max = false;
         }
     }
 
     //moving the platform
     if(Vert){ // Verticle movement
         if(!max) {
             transform.position.y += step;
         } else {
             transform.position.y -= step;
         }
     } else {  //Horizontal movement
         if(!max){
             transform.position.x += step;
         } else {
             transform.position.x -= step;
         }
     }
     
 
 }
avatar image hamcola · Feb 17, 2015 at 05:51 PM 0
Share

The above is 1 of my movement scripts

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by tanoshimi · Feb 17, 2015 at 05:56 PM

You have written your movement scripts to be tied to the framerate of your game (which varies from machine to machine, and even from one moment to the next on a given machine).

If your computer runs at 60FPS, your object is moving "step" amount 60 times every second. If your computer slows down (perhaps your antivirus program starts a hard drive scan, or some other background process is running) and your framerate drops to 30FPS, your object will half its speed too.

You need to learn about Time.deltaTime to make your objects move the same speed, whatever the framerate at which your game is running.

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 hamcola · Feb 17, 2015 at 06:16 PM 0
Share

Thanks tanoshimi, I will check out Time.deltaTime now!

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

< cheaper than <= ? 2 Answers

Movement speed of player is much slower in build than in the editor 3 Answers

Need help optimizing grid initialization. 1 Answer

How significant is the performance difference between a jagged array and a multidimensional array? 1 Answer

Wild fluctuations in performance when built into an exe... 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