[Resolved] Problem with player movement

Hi all

In my game the player drags his character left and right across the screen - constrained to the x axis. The problem I am having is that if the player moves his finger too fast the character gets left behind.
The way I am doing it is to check the ‘moved’ phase of a touch event and move the character.x to the touch x co-ord. Is there a better way of doing this (I’m assuming there must be!).

Many thanks
Chris [import]uid: 7841 topic_id: 32910 reply_id: 332910[/import]

Hello,
If you want something to always track a motion (fast or slow) a better option is to place a touch listener on the screen itself (Corona “stage”), not on the object to be moved. For “moved” events on the screen, you just snap the object to that location.

If you want a “trailing follow”, and the object is a physics object, you can set up a touch joint, which is like a theoretical physics joint between the object and your touch location, with a simulated elasticity and force pull… imagine dragging the object around by a flexible elastic string. This method is more effort than the snap method above, but it can give a more natural and smooth overall effect.

Best of luck,
Brent [import]uid: 9747 topic_id: 32910 reply_id: 130780[/import]

Hello,
If you want something to always track a motion (fast or slow) a better option is to place a touch listener on the screen itself (Corona “stage”), not on the object to be moved. For “moved” events on the screen, you just snap the object to that location.

If you want a “trailing follow”, and the object is a physics object, you can set up a touch joint, which is like a theoretical physics joint between the object and your touch location, with a simulated elasticity and force pull… imagine dragging the object around by a flexible elastic string. This method is more effort than the snap method above, but it can give a more natural and smooth overall effect.

Best of luck,
Brent [import]uid: 9747 topic_id: 32910 reply_id: 130780[/import]

Brent, you’re a legend! Many many thanks :slight_smile:
I had to put in a check to make sure the initial touch is within the width of the player characters space and set a flag on the player to say it was being touched, or else you could touch anywhere and it would just jump straight to where you touched, then when the event phase is ended it sets the move flag back to false. Does that make sense? [import]uid: 7841 topic_id: 32910 reply_id: 130856[/import]

Brent, you’re a legend! Many many thanks :slight_smile:
I had to put in a check to make sure the initial touch is within the width of the player characters space and set a flag on the player to say it was being touched, or else you could touch anywhere and it would just jump straight to where you touched, then when the event phase is ended it sets the move flag back to false. Does that make sense? [import]uid: 7841 topic_id: 32910 reply_id: 130856[/import]