Major difference from simulator to iPhone?

Hi,

I’m making a game where there’s a ball that bounces on a platform. Note that I’m using a custom physics engine I wrote and not the built in Corona physics. In the simulator, when the ball hits a platform, my bounce back works really nicely. On the actual iPhone device, the same part of the physics engine will fail and the ball will go through the platform. Also, to be clear, this discrepency between the simulator and device is before any user input. Meaning no touch input/mouse input is involved to throw in variables. It’s simply a ball starting to fall with some pre-set gravity and acting differently in each.

I guess this question is more general than anything, but is it normal for game physics/code to run completely differently in the simulator compared to how it runs on the device? Is there anything I might be doing that could cause this? It’s going to be extremely hard to write and debug my game if everything looks great in the simulator and then acts completely differently on the corresponding device.

Any insight is greatly appreciated. [import]uid: 6678 topic_id: 26861 reply_id: 326861[/import]

Is there anything I might be doing that could cause this?

I think that’s pretty much 99% certain.
What does your collision code look like? [import]uid: 108660 topic_id: 26861 reply_id: 109025[/import]

I’d second the above. In my experience physics on iOS devices tends to be very consistent between the simulator and device. [import]uid: 52491 topic_id: 26861 reply_id: 109033[/import]

My colissions are a little difficult because the platforms are very thin, so I needed to take into account where the ball was going to be next time the velocity was added to it so it wouldn’t go through platforms.

My simple hit test looks like this (c is the ball object, r is the platform object, and v is the velocity that the ball currently has, but hasn’t yet been added to its y:
[lua]boundingBoxHit2 = function(c, r, v)
if ((c.y + c.height/2) + v >= (r.y - r.height/2)) then
if ((c.x <= (r.x + r.width/2)) and c.x >= (r.x - r.width/2)) then
return true;
end
end
return false;
end[/lua]
I have a more precise one I like to run after, but I want to get this one to work on the device first.

If that detects a hit, I do the following to position the falling ball:
[lua]gameBall.y = gameFloorDisplays[i].y - gameBallRadius - (gameFloorDisplays[i].height / 2);[/lua]
gameFloorDisplays[i] is the platform in the loop that the ball was about to/is hitting.

I’m open to any suggestions and any ideas are appreciated. Though like I stated, this works great in the simulator. I’m simulating for iPhone 4 and testing on an iPhone 4S. When testing on the xCode simulator, it exhibits the same behavior as on the actual device.

Also, I pretty much agree with the consensus. When I used Corona back in 2010 to make a game similar game, I can’t remember any times when there was such a significant simulator/device discrepancy. That’s why I find this so odd and a little worrisome. [import]uid: 6678 topic_id: 26861 reply_id: 109119[/import]

Actually the code looks OK.
Which I guess is bad news.
I was looking for an == , which is dangerous when floating point numbers are about.

the code is doing more work than it needs to, by the way.

boundingBoxHit2 = function(c, r, v)  
 if ((c.y + c.height/2) + v \>= (r.y - r.height/2)) then  
 if ((c.x \<= (r.x + r.width/2)) and c.x \>= (r.x - r.width/2)) then  
 return true;  
 end  
 end  
 return false;  
end  

c.height/2 doesn’t need to be calculated every time.
have a module level constant , just like you did with gameBallRadius
same with r.height/2

and

if ((c.x <= (r.x + r.width/2)) and c.x >= (r.x - r.width/2))

could boil down to

if math.abs(r.x - c.x) < halfoftheplatformwidth then

… none of which answers your question but it should speed things up a bit. :slight_smile:
[import]uid: 108660 topic_id: 26861 reply_id: 109123[/import]

jeff472, thanks for the advice, I appreciate it. I’d definitely love to start doing optimization on my game, but in all honesty, as of now that’s useless. I don’t even know if I can continue development with this issue as my whole game depends on this element. I guess I might have to re-write it, but I’m not even sure how to begin being that the game works beautifully in the simulator. [import]uid: 6678 topic_id: 26861 reply_id: 109160[/import]

Hmm, well, to my delight, after getting desperate and going from stable release to the latest daily build, it seems to be working as expected. I’ll take it! [import]uid: 6678 topic_id: 26861 reply_id: 109162[/import]