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 JoshMBeyer · Mar 14, 2014 at 08:31 PM · animationlaggameplayglitching

Lag type issue?

I am making a game, and It was working just fine. My computer has 16gigs of ram. 2TB of HDD space, 4.2ghz processor. So I highly doubt my computer is the issue since i can do just about anything on it and there is not much stuff in the scene so far. I can't figure out why all of a sudden it has a lag? or some sort of conflict that is making everything glitchy. I found that the player is the issue. The movement script laggs the game dramaticly. What in this script is causing the problem?

 using UnityEngine;
 using System.Collections;
 
 public class PlayerControl : MonoBehaviour {
 
     public float speed = 10.0F;
     public float rotationSpeed = 100.0F;
 
     void Update() 
     {
         float translation = Input.GetAxis("Vertical") * speed;
         float rotation = Input.GetAxis("Horizontal") * rotationSpeed;
 
         translation *= speed * Time.deltaTime;
         rotation *= rotationSpeed * Time.deltaTime;
 
         transform.Translate(0, 0, translation);
         transform.Rotate(0, rotation, 0);
 
 
         if (Input.GetKey (KeyCode.W) || Input.GetKey (KeyCode.A) 
             || Input.GetKey (KeyCode.S) || Input.GetKey (KeyCode.D))
         {
             animation.Play ("Run");
             
         } else 
         {
             animation.Play("Idle");
         }
 
 
 
 
     }
 }
 
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 whydoidoit · Mar 14, 2014 at 08:45 PM

You are calling the animation system every frame. That's not a good plan. Presumably you are starting the Idle animation every frame again and again - also when you press a key you are starting the Run animation every frame the keys are held down.

You want to call the Play on the animation when something changes, not every frame.

Comment
Add comment · Show 2 · 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 JoshMBeyer · Mar 14, 2014 at 08:47 PM 0
Share

How would you suggest i do that?

avatar image whydoidoit · Mar 14, 2014 at 08:49 PM 0
Share

Hold some kind of state for the current mode of the character. Like an enum variable or an int.

When you are in the idle state detect a move to run, when you stop running move back to idle. Play your animation on each of those changes. Or use mecanim which kind of does this for you.

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

21 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

Related Questions

How do I prevent animation lag on bones? 1 Answer

Why does my animation jump/lag when activating a game object? 0 Answers

Enemy count is needed to be around 75-150, is this possible? 1 Answer

Why does simple animation make my game lag? 2 Answers

Animation Lag 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