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 Xysch · Jan 07, 2015 at 10:52 PM · playerbuglag

4.6.0 to 4.6.1 makes player lag, bug?

Hi, so I was working on a prototype for my game and was using the 4.6.0 version. When I updated to the current version of 4.6.1, my character seemed to randomly start lagging and I have no idea why. I used the same code for both of them and made no modifications. To make my player move I used rigidbody2D.AddForce. I've tried uninstalling and re-installing unity multiple times and keep having the same problem. A weird though, the background doesn't lag, just the player does. I made a little demonstration and uploaded it to YouTube:

4.6.1 Video

4.6.0 Video

Could it be a problem with one of my settings? I know that on the 4.6.1 Release Notes it mentions something about Physics2D and such. I thought this was the reason but it doesn't mention anything about the AddForce function.

Here's the code I used. The movement code is in the update function and I don't see any problems with it:

 using UnityEngine;
 using System.Collections;
 
 public class Player : MonoBehaviour {
 
     public float speed = 4f;
     public bool surfaceTouch = false;
     public bool SurfaceFall = false;
     public ParticleSystem Splash;
     public ParticleSystem Sand;
     public ParticleSystem AirBubbles;
 
     private Animator anim;
 
     // Use this for initialization
     void Start () {
         rigidbody2D.gravityScale = 0;
         Sand.emissionRate = 0;
         Splash.emissionRate = 0;
         AirBubbles.emissionRate = 0;
         anim = gameObject.GetComponent<Animator> ();
         StartCoroutine (bubbleAir ());
     }
 
 
 
 
     
     // Update is called once per frame
     void Update () {
     
 
         if (Time.timeScale == 1) {
             //Face Mouse
             Vector3 mousePos = Input.mousePosition;
             mousePos.z = 0f;
             
             Vector3 objectPos = Camera.main.WorldToScreenPoint (transform.position);
             mousePos.x = mousePos.x - objectPos.x;
             mousePos.y = mousePos.y - objectPos.y;
             
             var speedTurn = 500f;
             
             float angle = Mathf.Atan2 (mousePos.y, mousePos.x) * Mathf.Rad2Deg;
             Quaternion qTo = Quaternion.Euler (new Vector3 (0, 0, angle));
             transform.rotation = Quaternion.RotateTowards(transform.rotation, qTo, speedTurn * Time.deltaTime);
 
 
             //Movement
             var pos = Input.mousePosition;
             pos = Camera.main.ScreenToWorldPoint (pos);
             var dir = pos - transform.position;
             rigidbody2D.AddForce (dir * speed);
         }
 
 
         //Animation
         anim.SetInteger ("state", 0);
         var absVel = Mathf.Abs (rigidbody2D.velocity.magnitude);
         if (absVel < 1f) {
             anim.speed = 0.1f;
         } else     if (absVel > 1f && absVel < 3f) {
             anim.speed = 0.3f;
         } else     if (absVel > 3f && absVel < 5f) {
             anim.speed = 0.7f;
         } else     if (absVel > 5f) {
             anim.speed = 1f;
         }
     }
 
 
 
 
     void OnTriggerEnter2D(Collider2D col){
         if (col.gameObject.tag == "Surface") {
             //Splash
             if(surfaceTouch == false){
                 surfaceTouch = true;
                 Splash.gravityModifier = -1;
                 Splash.emissionRate = 100;
                 StartCoroutine(splash());
             }
         }
         //Sand
         if (col.gameObject.tag == "Floor") {
             var absVelY = Mathf.Abs (rigidbody2D.velocity.magnitude);
             if (absVelY > 1) {
                 Sand.emissionRate = 30f;
                 StartCoroutine (stopSand ());
             } else if (absVelY < 1) {
                 Sand.emissionRate = 15f;
                 StartCoroutine (stopSand ());
             }
         } 
     }
 
 
 
 
 
     void OnCollisionEnter2D(Collision2D col)   {
         if (col.gameObject.tag == "Surface") {
             var absVelY = Mathf.Abs (rigidbody2D.velocity.y);
             if(absVelY < 0.5){
                 rigidbody2D.gravityScale = 0.6f;
                 SurfaceFall = true;
                 StartCoroutine( SurfaceDown() );
             } else if (absVelY < 1 && absVelY > 0.5){
                 rigidbody2D.gravityScale = 1f;
                 SurfaceFall = true;
                 StartCoroutine( SurfaceDown() );
             } else if (absVelY > 1){
                 rigidbody2D.gravityScale = 1.5f;
                 SurfaceFall = true;
                 StartCoroutine( SurfaceDown() );
             }
         }
     }
 
 
 
 
 
 
     //spash
     IEnumerator splash(){
         yield return new WaitForSeconds (0.3f);
         Splash.gravityModifier = 1f;
         yield return new WaitForSeconds (0.4f);
         Splash.emissionRate = 0;
         surfaceTouch = false;
     }
     //Sand
     IEnumerator stopSand (){
             yield return new WaitForSeconds (0.5f);
             Sand.emissionRate = 0;
     }
     //Surface
     IEnumerator SurfaceDown(){
         if (SurfaceFall == true) {
             yield return new WaitForSeconds(0.2f);
             rigidbody2D.gravityScale = 0;
             SurfaceFall = false;
         }
     }
     //Air bubbles
     IEnumerator bubbleAir(){
         var bubbles = 5;
         while(bubbles > 0){
             yield return new WaitForSeconds (10);
             AirBubbles.emissionRate = 7f;
             yield return new WaitForSeconds(2);
             AirBubbles.emissionRate = 0f;
         }
     }
 
 }
 

If you have any ideas what this could be, I'm all ears! Thanks!

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

Answer by jpthek9 · Jan 08, 2015 at 04:50 PM

My guess is right now your Rigidbody (character) is calculating its position inconsistently. Either that, or you're not using Time.deltaTime to make the movements frame-independent.

Do physics in FixedUpdate and if you already are, set the Fixed Timestep in your Time Manager to be lower (http://docs.unity3d.com/Manual/class-TimeManager.html). You can also set Rigidbody.interpolate so updates automatically interpolate your Rigidbody's position.

Also, make sure you multiply calculations by Time.deltaTime so a faster or slower frame rate doesn't affect you. http://docs.unity3d.com/ScriptReference/Time-deltaTime.html

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

25 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 avatar image avatar image

Related Questions

Release Unity Player as open-source? 1 Answer

,Unity 2020 Player mesh bug 0 Answers

Network Game: How to solve : problem Lag or Refresh frame? 1 Answer

Player not able to handle edges of blocks? 0 Answers

my lives system is buggy 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