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 reppiz01 · Nov 11, 2014 at 12:33 PM · transformvsyncjerky

Why is my transform "stuttering" when I move it?

I know that there are several questions, but none of them could help me out :(

I have a Scene that just contains a Transform and the (non moving) Camera, and the only thing the Transform does is:

 this.transform.Translate(Vector3.left * speed * Time.smoothDeltaTime);
         
         if(this.transform.position.x < -200)
             this.transform.position = new Vector3(200, this.transform.position.y, this.transform.position.z);


Of course this Codesample is in the "Update"Method, I tried it with fixedUpdate, lateUpdate and also with time.DeltaTime, fixedDeltaTime...and so on,

i tried it with Vsync off, vsync every vertical blank and every second vertical blank, but there was no option how to get rid of the stuttering.

Sometimes its a bit better, sometimes its horrible. Without vsync for example, it looks like some parts of the Transform are faster moving than others, and it looks very very "glitchy" - with vsync one i have constantly "jumps" in the movement.

My Screen is running at 60hZ. The drivers are up to date - and I am really frustrated in this topic :(

So if somebody could help me, it would be great! Kisses and hugs for the "problem-solver" :P

Comment
Add comment · Show 12
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 MrSoad · Nov 11, 2014 at 12:47 PM 0
Share

Have you seen this post and tried moving it like this :

http://answers.unity3d.com/questions/444978/c-smoothing-out-transformtranslate.html

avatar image reppiz01 · Nov 11, 2014 at 12:57 PM 0
Share

i have seen it, anyway, I tried it again: Lerp doesn´t smooth it out (and it also geht´s slower at the end), and Vector3.$$anonymous$$oveTorwards doesn´t either...

:(

avatar image CHPedersen · Nov 11, 2014 at 12:57 PM 0
Share

One thing that comes to $$anonymous$$d is that you're using Vector3.left which is shorthand for the global x-axis, but transform.Translate is actually relative to the object's local coordinate system when you omit the RelativeTo parameter.

I don't suppose there's something odd going on with the object's local space, i.e. is the transform childed to the camera, and the camera happens to have non-uniform or animated scaling?

avatar image reppiz01 · Nov 11, 2014 at 01:02 PM 0
Share

well because Vector3.left is just (-1,0,0) i think it should work. But I´have also tried to set the transform coordinates directly, and also with moveTorwards.

The transform is not childed to the camera, the camera is the cam that gets created when you create a new scene, no changes, just orthogrpahic mode. The transform is just a plane with a texture on it, but I have the same results with a normal cube, and is not appended to the camera.

avatar image reppiz01 · Nov 11, 2014 at 01:06 PM 0
Share

I have filmed the behaviour with my mobilephone-camera:

https://www.youtube.com/watch?v=Y0Fp-XyA9vQ

Show more comments

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Landern · Nov 11, 2014 at 01:27 PM

Couple things, if you don't cache your transform the script is attached to, it's akin to using GetComponent each time you use 'this.transform', this can add up really quickly.

Since it hidden with in the text:

Little known fact: all of the component accessors in MonoBehaviour, things like transform, renderer, and audio, are equivalent to their GetComponent(Transform) counterparts, and they are actually a bit slow. GameObject.FindWithTag has been optimized, but in some cases, for example, in inner loops, or on scripts that run on a lot of instances, this script might be a bit slow.

Also it's better to copy the position struct, make modifications and assign it back, this directly applies to c#, though under the covers Java/UnityScript is performing this same action.

See if this is helpful.

 using UnityEngine;
 using System.Collections;
 
 public class MovementText : MonoBehaviour {
     float speed = 2.0f;
     Transform me;
     Transform cam;
     // Use this for initialization
     void Start () {
         me = this.transform; // Cache Transform of script attached to object, otherwise GetComponent is used each time.  This changes in Unity 5.
         cam = Camera.main.transform;
     }
     
     // Update is called once per frame
     void Update () {
         me.Translate(Vector3.left * speed * Time.deltaTime, cam);
         if(me.position.x < -200)
         {
             //Instantiating can be costly, copy the struct and reapply to object
             Vector3 posCopy = me.position; // You retain the original values, modify what you need.
             posCopy.x = 200;
 
             me.position = posCopy;
         }
     }
 }
 


Comment
Add comment · Show 30 · 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 haim96 · Nov 11, 2014 at 01:32 PM 0
Share

from your video it looks like vsync issue. did you disabled vsync for better frame rate?

avatar image reppiz01 haim96 · Nov 11, 2014 at 01:36 PM 0
Share

i tried it with vsync 0, 1 and 2.

there are difference, with vsync off it is very glitchy, with vsync 1 it stutters, and with vsync2 its almost horrible.

avatar image reppiz01 · Nov 11, 2014 at 01:35 PM 0
Share

thanks for the hints - I tried it with your code, but it doesn´t seem to affect anythng.

avatar image CHPedersen · Nov 11, 2014 at 02:39 PM 2
Share

I'm shooting in the dark here (which is why I never posted a definitive answer, but only comments. ;) ), but if you have Pro, or perhaps an active Pro trial, try opening your Profiler and see if there are any spikes that appear simultaneously with the stuttering. I can't imagine why there would be when the scene is otherwise totally empty, but you never know, could be something weird going on.

If you do see a profiler spike with the stutter, click it to view details for the frame where that spike occurred, then exa$$anonymous$$e the hierarchy to see what it is that takes longer.

avatar image drod7425 · Nov 11, 2014 at 02:44 PM 1
Share

@reppiz01 That code doesn't compile. targetPosition isn't declared. Is that really your full script?

avatar image CHPedersen · Nov 11, 2014 at 02:54 PM 1
Share

reppiz: The RenderTexture.SetActive you're seeing in the profiler does not stem from your own code. Remember that the editor is itself a 3D application. The RenderTextures in use are the editor's windows themselves, e.g. Game + Scene.

Do a build of your game and run it externally, then see if the stuttering persists.

Show more comments
avatar image
0

Answer by Nerigha · Nov 11, 2014 at 03:05 PM

Have you tried to implement physics for that object? Given a speed, you can determine the distance (current position of your object) in a given time. Speed = distance / time => distance = speed * time. I'll give you a short example:

 public class script : MonoBehaviour
 {
     private float speed = -2f;
     private Vector3 startPosition;
     private float startTime;
     private static Vector3 currentPosition;
 
     void Start ()
     {
         startTime = Time.time;
         startPosition = new Vector3 (this.transform.position.x, this.transform.position.y, this.transform.position.z);
     }
 
     void Update ()
     {
         float elapsedTime = Time.time - startTime;
         currentPosition = new Vector3(startPosition.x + (speed * elapsedTime), startPosition.y, startPosition.z);
     }
 
     void LateUpdate ()
     {
         this.transform.position = currentPosition;
     }
 }

Comment
Add comment · Show 4 · 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 reppiz01 · Nov 11, 2014 at 03:16 PM 0
Share

thanks. i tried your code (just with a bigger speed value), but the stuttering still persists.

avatar image Nerigha · Nov 12, 2014 at 11:30 AM 0
Share

I've added a light (directional), saved the scene and the project and build. Running it outside of unity seems to be ok, no stuttering. (Or my eyes are stuttering too :) )

avatar image reppiz01 · Nov 12, 2014 at 12:28 PM 0
Share

tried to add directional light and made a webbuild. same stuttering as ever :( - i really run out of ideas how to fix this...

avatar image reppiz01 · Nov 14, 2014 at 11:43 AM 0
Share

:-( this is so damn frustrating

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

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

Related Questions

Smoother Camera Movement without making camera child of the player? 0 Answers

Jerky motion using moveTowards at high speed 0 Answers

sprite moves jerky no matter on frame rate 2 Answers

Stuttering graphics with VSync on 1 Answer

How to place a transform on the center of one face of a cube 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