• 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
1
Question by ryf9059 · Jun 08, 2013 at 01:59 PM · movementupdatetranslatedeltatime

Choppy movment for even the most basic stuff

I'm using the following code for updating my player.

 void Update () {
     float hori = Input.GetAxis("Horizontal");
     float ver = Input.GetAxis("Vertical");
     Vector2 transVector = new Vector2(hori, ver);
     transform.Translate(transVector * 5 * Time.deltaTime);
 }


But when running the movment is choppy, should I say, jumpy, because it shakes left and right.

I then created a new project with only a single cube in it and the same script. But it is still choppy when hit run, noted the fps is at 60. This happens intermitently and isn't that serious, but still, even the slightly choppy moment is unbearable since this is such a simple scene.

Note: only translation is suffering from this choppy movement, all other animations are rendered smoothly in the game. So I can only think of this as not updating in constant frame. But I already have Update and DeltaTime used, why will this happen?

Please advise.

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

Answer by Owen-Reynolds · Jun 08, 2013 at 03:28 PM

Do you have a camera targeting the player? If so, try it with a fixed (script-less) camera. Sometimes the jerkiness is really in the camera positioning.

Sometimes the editor, will be a little jerky. It's handling the extra windows that won't be in the real game. That comes and goes. If you try a Build&Run you'll see the "real" look of the game.

Otherwise, your code runs nice and smooth for me.

Comment
Add comment · Show 7 · 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 ryf9059 · Jun 08, 2013 at 03:36 PM 0
Share

I first have a camera targeting the player by making it a child, and then I noticed the jerkyness and detached it. Now I found out that the jerkyness comes from the player translation.

Since I'm making a 2D game and I'm on a high-end alienware laptop so I assume that won't be too much overhead.

However, I guess this might have something to do with my video card: Raedom HD 6970, a pretty good one, but it's about to die: it cranks up to 100C just by playing some clip, and often has driver crash, frame rate drop etc, etc. Not sure if this actually affects the game since I tried my project on another desktop computer with nvidia card and it's having the same issue (unless they are both bad...)

BTW how do I build and run from the editor?

avatar image Owen-Reynolds · Jun 08, 2013 at 03:59 PM 0
Share

But does the camera have a script targeting the player?

I've found "editor jerk" is very intermittent, so probably not that if the player jerking is consistent. But, Click Edit-> Build; add your scene; click build&run.

If the bad computer was the problem, everything would probably have the same jerkiness.

Is it spraying errors as it runs? But that would also result in a global frame-rate issue, not just the player.

avatar image ryf9059 · Jun 09, 2013 at 05:06 PM 0
Share

I used to, but then I removed the script and attached it to the player as a child so it follows natually.

$$anonymous$$ove over, I move the script and detached the camera so it's not following the player at all and I see jerky movement on the player.

It's not spraying errors of any kind, I guess the problem is the "editor jerk", tho it happens only on translation on certain object (says if I have a slighly complex scene have have object translating at different speed in the background, some will have jerky movement and some don't, again they all use the same translate method).

Also I cannot find Build under Edit in Unity editor, only Play and some other options.

avatar image Owen-Reynolds · Jun 09, 2013 at 10:26 PM 0
Share

I'd guess you've got something set funny somewhere. $$anonymous$$aybe start a fresh scene, don't even touch the camera except to aim it, and put that script on a cube. I'd imagine it will look fine (it did for me.) Then back-engineer what was wrong in the original scene.

The editor doesn't have any special problems with Translate -- it just sometimes can drop frames a little more that playing for real, or have a funny border, and very rarely. Build is in File (sorry,) but I doubt that's it.

avatar image ryf9059 · Jun 10, 2013 at 06:13 AM 0
Share

I build it and it worked smoothly. Thanks! But I also have a question: for the update option there is Update and FixedUpdate, and I know the differences: FixedUpdate is called per time interval and Update is called per frame? If that's the case there is no need to use deltaTime in FixedUpdate right? In fact why should there be deltaTime at all? Just put everything in FixedUpdate and leave the Update blank since it's not framerate stable.

Show more comments
avatar image
0

Answer by bubzy · Jun 08, 2013 at 02:18 PM

you might try this http://docs.unity3d.com/Documentation/ScriptReference/Vector2.Lerp.html

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 Owen-Reynolds · Jun 08, 2013 at 03:20 PM 1
Share

$$anonymous$$oving with Lerp assumes you have some known target point and want to gradually reach it over several frames by adding a constant amount. For example, if tapping an arrow key made you slide over to the next board position.

Also, Lerp is just math -- it doesn't have any secret smoothing sauce. pos=Lerp(A,B, 0.3f); is just a shortcut for pos = A + (B-A)*0.3f;.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

16 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

Related Questions

Movement using Time.deltaTime not working on Fast mac 3 Answers

Moving objects performance in PC and Editor 0 Answers

Movement lag, jitery every few seconds 1 Answer

How to translate a camera forward and back(basically a zoom) according to the distance of two objects? 1 Answer

Disable Diagonal Move 2 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