Page 1 of 1

Flicking Objects

Posted: Mon Mar 26, 2012 8:22 pm
by laingm
I trying to create physics that simulate hitting a ball by "swiping" or "flicking" it with the mouse/touch. Right now how I am approaching this is by creating a body (not added to the space) that is locked onto the mouses position and I update its position every loop. Then I have a joint connecting the "mouse body" to another "touch body" that is actually added to the space (this way it updates its velocities and performs collisions and such).

The problem I am having is that if you swipe to fast, there is no collision with the ball, or the ball barely moves (I'm guessing because there is only a tiny impulse for one step so it is not noticeable). What can I do to increase performance on this and make sure that no swipes go through the ball? Is this the best way to approach it? I have tried using a smaller step (currently 1/60.0f) and also tried increasing iterations (currently at 10). Is there anything else I should try or a better method such as raycasting that I could use to make this sort of physics?

Also I am currently removing the body after the collision seperate function because if I don't sometimes I swipe through the ball and then the ball runs into my swipe and bounces backwards. Any better way than removing the touch completely to avoid this?

Thank you!

Re: Flicking Objects

Posted: Tue Mar 27, 2012 10:43 am
by slembcke
It sounds like you really just want the mouse control code from the demo project and you've basically implemented it. Are you also updating the velocity of the invisible body for the touch? If not, it will only apply position correction forces to the object you touch and it will feel really mushy.

Re: Flicking Objects

Posted: Wed Mar 28, 2012 4:28 pm
by laingm
Would it be possible for you to please walk me through what each step in the cpArbiterApplyImpulse function is doing?

I am guessing that n is the normal to the collision, but what exactly are r1 and r2?

What is the bias impulse?

What is the normal impulse?

And what is the friction impulse?

If I can understand these then I will be able to implement my own collion handler to fix my touch from going through the ball.

Thanks!