Hi,
I’m trying to solve a particular issue of supporting some simple physics scaling between devices with multiple resolutions, but I’m running into some problems. I was hoping that I would just be able to scale the force(s) applied to my objects based on the difference in resolutions to accomodate for the larger screens, but it doesn’t seem to give 100% perfect results. Here’s an example of what I’m doing:
[lua]xForce = 300;
yForce = 400;
newForce = xForce * (display.viewableContentWidth/480);
newForce = yForce * (display.viewableContentHeight/320);[/lua]
xForce and yForce could equal any amount, but we’ll use -300 and -400 as an example. So, in my game, I’m firing objects using object:applyForce(). I need to be sure that the object hits a target object at a certain distance away, which is currently no problem. The problem occurs when I move into a different environment from my standard iPhone resolution of 320x480 into, say, an Amazon Fire resolution of 1024x600.
I’ve tried scaling everything uniformly, so positioning the object to be fired would look like this:
[lua]xForce = -300;
yForce = -400;
xPos = 250;
yPos = 200;
targetObjectX = 50
targetObjectY = 30
newForceX = xForce * (display.viewableContentWidth/480);
newForceY = yForce * (display.viewableContentHeight/320);
newPosX = display.viewableContentWidth * (xPos/480);
newPosY = display.viewableContentHeight * (yPos/320);
newTargetObjX = display.viewableContentWidth * (targetObjectX/480);
newTargetObjY = display.viewableContentHeight * (targetObjectY/320);
objectToFire:applyForce(newForceX, newForceY, objectToFire.x, objectToFire.y)[/lua]
However, my issue seems to be that increase the Force by a uniform about according to the new change in distance doesn’t seem to guarantee that it will have the force required to travel the new distance. I’ve even tried scaling my gravity as well, as such:
[lua]physics.setGravity(0, 15 * (display.viewableContentHeight/320));[/lua]
All of the X values are scaled by the new contentWidth divided by 480 because 480 was the original width of the resolution on the iPhone simulator that I was using. All Y values are scaled by the new contentHeight divided by 320 for the same reason as mentioned before, 320 was my original height on my iPhone simulator.
So, is this a viable solution and perhaps I’ve messed up somewhere down the line with my math? Or will scaling the Force on a 1:1 scale with the increased distance between the starting point and the target not result in the proper amount of force necessary to propel the ball over the new distance?
Thanks for any advice! [import]uid: 138013 topic_id: 28334 reply_id: 328334[/import]