Same physics in SpriteKit regardless of size of object in iPad and iPhone
Asked Answered
P

1

6

I have ball that is bouncing around the scree, something like pong.
Radius of ball depend on the with of screen.

I have found that ball is not going with same speed on iPhone and iPad.
Because ball is bigger on iPad, so it has bigger ball.physicsBody.mass.

Question How to properly fix this ?
I have found two way:
First is: SpriteKit iPhone/iPad different resolution, need same physics to change SKPhysicsWorld. Second is: SpriteKit ball speed differ on size to fix mass of ball.

I think that fixing the massof ball is proper way.
Am I correct ?

Pace answered 22/7, 2014 at 8:28 Comment(4)
Why not do a quick test? Increase mass relative to the size difference of the circle shape, see if it behaves the same on both devices. I don't think it will though because there may not be a linear relation to mass and shape size. Even then you would have to scale up the mass for all other bodies too, as well as gravity, in order to ensure at least similar collision behavior.Austreng
I have done those test and on SpriteKit and what I can say for sure is that speed depend on mass linearly, but I have not seen liner relation between size/area/volume and mass. This look to me as very common problem. If you make game like pong, you want same movement of ball on all devices. So I was hoping that somebody, who have solved it, can give some experience how he solved it.Pace
My previous comment is wrong, because I did calculations on calc and did some rounding. After putting everything in excel (and doing CORREL function) I can say that everything is liner e.g. mass to shape size.Pace
So in the end which way did you go with and how did you do it? Because none of this is working for me.Bluefarb
P
0

App in which I have used this approach can been seen at:
https://itunes.apple.com/us/app/pongfinity/id930801337

I have done following:

I have fixed: friction, restitution, linearDamping, and mass, all properties on ball physicsBody.

I used function written by myself:

NSUInteger normalizeForHeight(NSUInteger number)
{
    CGRect  screenRect   = [[UIScreen mainScreen] bounds];
    CGFloat screenHeight = screenRect.size.height;



    CGFloat factor = 1.0;
    factor = screenHeight / 480;
    return (number * factor);
}

So every time when I am changing speed of the ball, I am using this normalizeForHeight(20) , 20 is just some constant I I picked.

Pace answered 28/2, 2015 at 8:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.