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
1
Question by difficultnerd · Jul 12, 2014 at 03:25 PM · graphicsframeratesmoothchoppy

Why is my character movement "jerky/stuttery/flickery/choppy"?

Hey everyone, I'm writing a game destined for mobile, where the player has a third-person view of an airplane. They move the plane by gyroscope. In the Unity Editor it's currently running at about 200 frames a second with about 9 draw calls.

There is nothing visible yet in my game, except the player's airplane.

For the sake of my sanity later, I want "input" to be handled by one script and "movement" to be handled by another script. The idea being that I can swap out input scripts when porting platforms (say for an accelerometer script, or a virtual game controller, or whatever)

When the gyro is below a certain deadspot value, nothing happens. When it is above this deadspot value, I call another script to move the airplane.

 GyroInput.js:
 
 function Update () {
     GyroAttitude = Input.gyro.attitude;
     
     
     if (GyroAttitude.y > GyroYDeadNeg && GyroAttitude.y < GyroYDeadPos) {
         print("resetting airplane");
         Player.GetComponent(AirplaneMovement).ResetAirplane();
         }
     
     else if (GyroAttitude.y < GyroBarrelRollPos && GyroAttitude.y > GyroBarrelRollNeg) {
         print("banking airplane");
         Player.GetComponent(AirplaneMovement).BankAirplane(GyroAttitude.y);
         }
     
     else if (GyroAttitude.y > GyroBarrelRollPos || GyroAttitude.y < GyroBarrelRollNeg) {
         print("barrell roll!");
     }
     
 }
 

fairly straight-forward - if the gyro's attitude is beyond a certain point, call the "BankAirplane" function of AirplaneMovement.js.

 function BankAirplane(attitude:float){
     // banks the airplane and moves it in the correction direction.
     // amount is the amount of the bank
     
     
     //variables for reading the plane's current position in world space
     var PositionX : float = transform.position.x;
     var PositionY : float = transform.position.y;
     var PositionZ : float = transform.position.z;
     var DestX: float;
     
     if (attitude < 0) SpeedMultiplierBank = SpeedMultiplierBank * -1;
     
     
     DestX = PositionX + (SpeedMultiplierBank * Time.deltaTime);
 
         
     if (DestX > PosXnegMax && DestX < PosXposMax){
 
     
         transform.Translate(SpeedMultiplierBank * Time.deltaTime, PositionY, PositionZ, Space.World);  //move the plane along the X access
         //write code to rotate the plane
         
         
     
     }
     
     //transform.Rotate(0,0,attitude * Time.deltaTime);  //this was my inital gyroscope test
     
     if (SpeedMultiplierBank < 0) SpeedMultiplierBank = SpeedMultiplierBank * -1;
     
     
 
 }


I haven't written my 'rotate the aircraft' bit yet because I'm trying to make the "move across the screen" bit smooth.

But it ain't!

Comment
Add comment · Show 1
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 difficultnerd · Jul 13, 2014 at 12:16 PM 0
Share

Here is a video to show the 'choppiness' in question - https://www.youtube.com/watch?v=fe_$$anonymous$$$$anonymous$$6TLO4U

4 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by difficultnerd · Jul 14, 2014 at 10:48 AM

Wow - Awest your comment solved another n00b issue I was having - my player game object was occasionally flying off to the edge of the game universe if I didn't have "resets" in my code.

The "cause" of this choppiness issue was that I had two transform.translate - one for Z and one for X - I've changed my logical so that I calculate the change in Z and the change in X and then call transform.translate only once per frame, and the problem is solved!

Here is the revised function if anyone needs it...

 function RepositionAirplane (attitude: float, power: float) {
 //these parameters are only used for 'direction' of input - there are 
 //tuning variables for adjusting speed.
 
     if (LoopInProgress == false){
         //variables for reading the plane's current position in world space
         var PositionX : float = transform.position.x;
         var PositionY : float = transform.position.y;
         var PositionZ : float = transform.position.z;
 
         
         var DestX: float;    // our X destination
         var DestZ: float;    // our Z destination
         
         var ApplyX : float;  //how much X to apply
         var ApplyZ : float;  //how much Z to apply
         
         
         
         
         // work out how much change in X we're going to apply for this frame
         
         if (attitude == 0) {
                 ApplyX = 0;
                 DestX = PositionX;
                 }
         else if (attitude < 0) {
                 ApplyX = SpeedMultiplierBank * Time.deltaTime * -1;
             
             }
         else if (attitude > 0){
                 ApplyX = SpeedMultiplierBank * Time.deltaTime;
             }
 
         
         // work out how much change in Y we're going to apply for this frame
         
         if (power == 0) {
                 ApplyZ = 0;
                 DestZ = PositionZ;
                 }
         else if (power < 0) {
                 ApplyZ = SpeedMultiplierPower * Time.deltaTime * -1;
             }
         else if (power > 0){
                 ApplyZ = SpeedMultiplierPower * Time.deltaTime;
             }        
 
         
         //work out what our destination X & Y points are
         DestX = PositionX + ApplyX;
         DestZ = PositionZ + ApplyZ;
         
         
         if (DestX < PosXnegMax || DestX > PosXposMax) ApplyX = 0;        // if the destination is less than the maximum X boundary, we're not moving
         if (DestZ < PosYnegMax || DestZ > PosYposMax) ApplyZ = 0;        // if the destination is less than the maximum X boundary, we're not moving
         
         
         transform.Translate(ApplyX, 0, ApplyZ, Space.World);  //move the plane
         
 
     }
 }
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
avatar image
3

Answer by awest · Jul 14, 2014 at 04:24 AM

I think your issue is with the transform.Translate function. I'm not sure what SpeedMultiplierBank is, but you are also moving it on the other axis by its own position. If you don't want it to move on the y and z axis, they should be set to zero, not the planes current position.

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 Kraken464 · Jul 14, 2014 at 10:53 AM 0
Share

Nice catch awest, I missed that completely!

avatar image
1

Answer by Kraken464 · Jul 14, 2014 at 01:29 AM

Ok so here is the question... do you have another place where you are controlling the movement of the plane? I see in the bankairplane function that you are using a transform.translate that is affecting the X only. It is going to conflict with anything else that is trying to translate the item. If you need to do this during the bank at the same time you are doing the base movement, then maybe consider putting the jet in a child object and do the bank on local translation.

I may be off, but in the video I saw it jump position while moving both on the x and y the most. I hope this gives you a different direction to search down!

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 difficultnerd · Jul 14, 2014 at 02:26 AM 0
Share

Hi $$anonymous$$raken, complete (current) versions of all my scripts (3) in this project are in this forum thread - http://forum.unity3d.com/threads/transform-position-randomly-thrown-to-the-end-of-the-universe.256761/

I'm having a weird issue where if I don't 'reset' my airplane position back within playable space, the transform is "thrown" to edge of the universe randomly.

avatar image
0

Answer by Kraken464 · Jul 14, 2014 at 01:27 AM

Ok it did not take the first time... long story short, I see that you are calling transform.translate on the X in the banking function. Are you calling it in another loop? It may be fighting position between two different scripts.

If that is the case, I would make the jet a child object and do the banking translation on the localposition, while using the parent object for all screen movement. I hope this helps!

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 difficultnerd · Jul 14, 2014 at 02:23 AM 0
Share

Hi $$anonymous$$raken - I've changed the script slightly for the video - I've expanded it to handle "vertical" movement as well.

Because of limitations in how I think, I like to keep my "input" separate from my "action" in all my code - Airplane$$anonymous$$ovement.js is the only script that moves the plane.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Frame Rate Problem 1 Answer

Editor playback performance on Windows 1 Answer

Choppy on iPhone only... 1 Answer

Performance/framerate issue 0 Answers

Why do my shadows look worse if I make my ground larger? 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