Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 StarWarrior · Oct 20, 2015 at 06:59 PM · updatevelocityphysics2dmobile devicesmathf.clamp

Is there any difference between mobile and desktop physics?

I have this code:

     void Update () {
         if (SystemInfo.deviceType == DeviceType.Desktop) 
         {
             float xMovement = Input.GetAxis("Horizontal");
             this.rb.velocity = new Vector2(xMovement, 0) * this.speed;
 
 
         } else if (SystemInfo.deviceType == DeviceType.Handheld) 
         {
             if (Input.touchCount > 0) 
             {
                 Touch touch = Input.GetTouch(0);
                 if (touch.position.x > this.westTouchBound && touch.position.x < this.eastTouchBound) 
                 {
 
                 } else 
                 {
                     this.speed = this.ballRigidBody.velocity.magnitude * 2.0f;
 
                     Vector3 location = this.gameCamera.ScreenToWorldPoint(touch.position);
                     
                     Vector3 delta = location - this.transform.position;
                     Vector2 course = new Vector2(delta.x, 0.0f);
                     course.Normalize();
                     this.rb.velocity = course * speed;
 
                 }
 
             } else 
             {
                 this.rb.velocity = new Vector2(0, 0);
             }
 
         }
         float eastMax = this.gameController.screenWidth / 2.0f - this.gameController.wallThickness - this.gameController.barWidth / 2.0f;
         float westMax = -eastMax;
         
         float actualX = Mathf.Clamp(this.transform.position.x, westMax, eastMax);
         this.transform.position = new Vector3(actualX, this.transform.position.y, this.transform.position.z);
 
     }
 

It doesn't allow the platform to leave boundaries. On desktop it works just well. On mobile when I move platform to side it just keeps jumping and bouncing off it. I have tried a lot: moving code to LateUpdate, assigning position of rigidbody, removing Mathf.Clamp with simple if-else, but that didn't work. Everything great on the desktop, and jumping and bouncing off the boundaries on mobile. Is there a way to fix it?

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

Answer by tanoshimi · Oct 20, 2015 at 09:55 PM

There's no difference in the physics engine. There's a difference in your code, because you're creating a branching logic using if (SystemInfo.deviceType == DeviceType.Desktop) to execute different behaviours.

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

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

Constant speed across mobile devices using 2D physics velocity? 1 Answer

Is calling OnCollisionEnter2D on allot of GameObjects bad for performance? 2 Answers

Continuous moving ball stuck at some time 0 Answers

How to disable a keypress after a certain amount of time? 1 Answer

How can I make a sprite object rotate to face another object using angularVelocity? 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