Posted: 7th Dec 2011 14:53
I made a simple game where balls fall off the top of the screen, and you have to catch them in a tincan, that only moves left and right.

I want to detect when a ball actually falls inside the tincan, not when it hits the sides of the tincan or hits halfway in - half way out (along x co-ords).

If you have an easy solution without using Physics, I can appreciate any help & ideas.

Thanks
Posted: 7th Dec 2011 15:00
Can you not have an invisible sprite which fills the bottom 3rd (or however much you need) of the tincan. Which also moves left and right with the tincan. Then just use 'GetSpriteCollision'?

EDIT: Reading your post again, are you saying that if a ball collides with the side of the tincan, then the tincan should pass through the ball? and not deflect it?
Posted: 7th Dec 2011 16:11
yes the invisible sprite at the bottom to trigger the hit is good.

However the problem is with the sides of the tincan and especially if the ball falls 1/3 in the opening of the can and 2/3 outside...
Posted: 7th Dec 2011 16:18
Ok, I hear yah... I'm not sure about that...

Quick question though, why don't you use physics and have it so that the tincan deflects the ball when it hits it... So if the ball falls on the top edge of the can, the ball deflects either in the can, or out (depending on how it fell)? Similarly, if you move the tincan right (or left) and it hits a ball on the side, it just pushes the ball out the way, rather than passing through? That way the above will work as a ball can only be either in the can or out, and no inbetween...
Posted: 7th Dec 2011 16:23
I am trying to avoid physics. my game currently runs at full 60fps on an iphone 3gs. if i switch on physics, the fps is dropping down quite a lot.
Posted: 7th Dec 2011 17:40
I struggle to believe that physics is having a noticeable effect on your fps...? Box2D is notoriously fast. I've had hundreds of physics objects on screen at one time with no slow down at all on my iPod touch. Are you sure it wasn't caused by something else?

Your problem can be solved without physics by using multiple thin 'dummy' sprites detecting collisions on the different edges. That's the simplest way to do it I'd say.
Posted: 7th Dec 2011 19:35
You don't need to check for collisions for such a simple idea. Just compare the x positions of the ball and the can. If the difference is too big then the ball is outside. You perform this check when the ball reaches a specific y position, when it would go into the can.
Posted: 7th Dec 2011 21:45
Baxslash, if i remove the physx, the game is back at 60fps!

i will try to implement a few dummy sprites and upon collision detection decide what fate the ball should have!

thanks a lot