- Home /
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?
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.
Your answer
Follow this Question
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