Flicking Objects

Official forum for the Chipmunk2D Physics Library.
Post Reply
laingm
Posts: 2
Joined: Mon Mar 26, 2012 7:35 pm
Contact:

Flicking Objects

Post 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!
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Flicking Objects

Post 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.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
laingm
Posts: 2
Joined: Mon Mar 26, 2012 7:35 pm
Contact:

Re: Flicking Objects

Post 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!
Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests