ChipmunkMultiGrab and endLocation

Discuss new features and future development.
Post Reply
horseshoe7
Posts: 36
Joined: Fri Feb 19, 2010 11:58 am
Contact:

ChipmunkMultiGrab and endLocation

Post by horseshoe7 »

I'm trying to achieve a result where I grab an object and slide it along a surface. I was hoping that when I release my finger, the grabbed object will have the velocity with which my finger was moving.

As I understand MultiGrab, if it's how the "mouse joint" of previous versions of Chipmunk worked, it's basically creating a spring between your grab point and the point on the screen where you're touching. (with rest length of 0, so the spring is always contracting, thereby making the grabbed shape trying to move towards your finger) This means any grabbed object isn't truly grabbed. What I'm noticing in the behaviour is consistent with that premise.

My problem is that I can really use a sort of 'slide to shoot' physics (imagine trying to shoot an air hockey puck with your finger on top of it, and not with the paddle) because the 'shot velocity' is not consistent. It results in there being only one way to shoot consistently, and doesn't really mimic real life in that most play testers of my game expect to see a different result based on their input.

I've also read in the past however that if I track the finger movement, then when releasing the grab I assign the grabbed shape's velocity directly, Chipmunk won't like that very much due to values that have been cached or something like that.

Perhaps there are good values for initWithSpace: withSmoothing: withGrabForce: that will help me get there, but I haven't seen this yet, and don't think I will unless it resolves 100% of the discrepancy between the two in less than one frame, but of course this might lead to really high velocities when I release my finger.

How bad is it to just set a body's velocity in any of the touch handlers (update and end) ? is there another solution?
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: ChipmunkMultiGrab and endLocation

Post by slembcke »

It's fine to set the velocity in the endLocation callback. The problem with modifying the velocity directly is when you try and do it every frame.

I think the problem with the inconsistent flicking results is that touch input is fairly noisy in both timing and location. The smoothing parameter is to compensate for that a bit. If you use too much smoothing, the grab will be really "mushy" and lag behind the user's finger a lot. If smoothing is set really low, then it will follow their finger quickly, but may have sudden velocity changes to do it. So your best bet is to keep the smoothing low and then calculate your own release velocity and apply that.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
horseshoe7
Posts: 36
Joined: Fri Feb 19, 2010 11:58 am
Contact:

Re: ChipmunkMultiGrab and endLocation

Post by horseshoe7 »

I'll give that a try.

I continue to be amazed at how well you support your lib and start to slowly believe you are super human and can slow down the passage of time so to get so much done! respect and thanks!
Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests