Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 Jyndie · Jul 29, 2018 at 12:22 PM · androidrigidbody2dvelocityphysics2dtimestep

Android velocity slower than editor

I am trying to move multiple player GameObjects when input is received. Here is the code that I wrote to do this:

     void FixedUpdate(){
         if (movementVector!= curMovementVector) {
             curMovementVector = movementVector;
 
             for(int i = 0; i < players.Count; i++) {
     
                 Rigidbody2D rb = players[i].GetComponent<Rigidbody2D>();
                 PlayerController playerController = players[i].GetComponent<PlayerController>();
 
                 rb.velocity = movementVector * speed;
 
                 switch(movementDirection) {
                     case "up":
                     case "down":
                         playerController.SetSize(movementDirection);
                         rb.constraints = RigidbodyConstraints2D.FreezePositionX; 
                         break;
                     case "left":
                     case "right":
                         playerController.SetSize(movementDirection);
                         rb.constraints = RigidbodyConstraints2D.FreezePositionY;
 
                         break;
                 }
             }
         }
     }

The movement vector is set on input. I update the velocity only when a new input is received.

But whatever I do the speed of the players on my android phone is slower than in the editor. I have tried profiling for perfomance issues and also multiplying by both Time.deltaTime and Time.fixedDeltaTime. But nothing seems to fix the issue.

EDIT:

I tried inserting just hardcoded values, but it remained quicker in the editor.

This is how I get the movement vector and the speed is just a float:

 void Update() {
         if (globalVariables.isCreating == false) {        
             if (swipeControls.swipeUp) {
                 movementVector = transform.up;
                 movementDirection = "up";
                 
             } 
 
             if (swipeControls.swipeDown) {
                 movementVector = -transform.up;
                 movementDirection = "down";
             } 
 
             if (swipeControls.swipeRight) {
                 movementVector = transform.right;
                 movementDirection = "right";
             } 
 
             if (swipeControls.swipeLeft) {
                 movementVector = -transform.right;
                 movementDirection = "left";
             } 
         } 
     }

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 JVene · Jul 29, 2018 at 04:05 PM 1
Share

Without code showing how movementVector and speed are calculated, there's almost nothing to offer.


If I assume speed is in meters per second and movementVector is influenced by user input, I could surmise that various platforms provide a metric of user input quite different from each other, which would require some "normalization" so as to unify the meaning of user input.


rb.velocity is an instruction to the physics engine to move the object for you over time, so indeed you wouldn't use deltaTime (or fixedDeltaTime - which doesn't mean what most think it means, according to the documentation - deltaTime is what code should use when that is required).


However, it isn't likely you must set velocity at every fixed update, but when user input implies a change to the velocity.


What is required is to debug by observing how different rb.velocity is being set on the two platforms, and since that comes from speed and movementVector, work backwards to where nd how those two are calculated until you see which parameter is different.


I would expect you haven't nailed down that the different observed speeds have factually used the same rb.velocity, right? Conduct and experiment to set rb.velocity to some fixed value that you can confirm works the same on both platforms.

0 Replies

· Add your reply
  • Sort: 

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

210 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 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 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 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 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 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 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

2D rigidbody velocity relative to rotation? 0 Answers

How to compensate Fixed TimeStep - speed in game 0 Answers

How can I get 2 rigidbody2d objects to "share" physics? 1 Answer

Adding a force to RigidBody2d - Velocity returns 0 1 Answer

Velocity doesnt change properly 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