Moving objects by finger

Topics: Developer Forum
Mar 2, 2011 at 8:25 PM

Hello.I used for moving objects code that I found in this site,but...

while (TouchPanel.IsGestureAvailable)
                GestureSample gesture = TouchPanel.ReadGesture();
               if (gesture.GestureType == GestureType.FreeDrag)//using Tap doesn't wotk also
                    offset = gesture.Position - _myBallFixture.Body.Position;
                    Vector2 positionDelta = _myBallFixture.Body.Position - (gesture.Position - offset);
                    Vector2 velocity = gesture.Delta / (1f / 10f);
                    //  MoveTo( gesture.Position);
                    _myBallFixture.Body.LinearVelocity = -velocity;
                //    _myBallFixture.Body.ApplyForce(Vector2.Divide(gesture.Delta, 2.0f));

This code doesn't work for me.I want to move objects with velocity by finger.For example this is realized in SimpleSamples, but I don't know how.
I want to develop my own collision/moving system.
Also I don't found method "if obj.IsPickedUp", how can I realize this?
Please somebody help me.

Mar 2, 2011 at 8:39 PM
Edited Mar 2, 2011 at 8:41 PM

gesture.Position is in pixels and _myBallFixture.Body.Position is in meters.  You need to convert your units to MKS.

Also, ideally use ApplyForce rather than modifying the velocity directly.

Regarding "picking up objects", that's out of scope for FPE since it's only a physics engine; what you can do is take the reading of the current gesture, apply a margin to it and check if the position of the reading intersects with the position of your body (again, you will need to convert between pixels and meters).

Mar 3, 2011 at 2:33 PM
while (TouchPanel.IsGestureAvailable)
                GestureSample gesture = TouchPanel.ReadGesture();
               if (gesture.GestureType == GestureType.Tap)
                    Vector2 gestrd = ConvertUnits.ToSimUnits(gesture.Delta);
                    Vector2 myBallpos = ConvertUnits.ToSimUnits(_myBallFixture.Body.Position);
                    Vector2 gestr=ConvertUnits.ToSimUnits(gesture.Position);
                    offset = gestr - myBallpos;
                    Vector2 positionDelta = myBallpos - (gestr - offset);
                    Vector2 velocity = gestrd / (1f / 10f);

            }//sorry for my bad code, it's only test
For me it also don't work.This sample I was took in some example....Can somebody tell me why it doesn't work?
Mar 3, 2011 at 6:29 PM

I haven't tried your code but can you explain a bit more on what you mean by "doesn't work" ?

Is the while block not entering, is the GestureType never a Tap or something else?  Put breakpoints and see if both while and if blocks are entered.

Mar 3, 2011 at 7:16 PM

This is my project ,it's modifed simplesamples.