Tap = move character to tap

Hi all, I’m relatively new to Corona, so please forgive me if there is a simple solution to this

I’m starting out creating an RPG, I have a nice little map which I can move around with a touch function, so that when I drag my finger around the map moves with it.

I also have a little character in there which I now want to move around.

The function I want is that when I tap once anywhere on the screen, the character will walk from its current position to the new position

I’m also thinking about having more than one character to control - in this case, would it be possible to first tap the character (make it the active character) and then tapping the map, that character only will walk to that new position?

Again, apologies if this is easy to do but I’ve been searching for / reading through tutorials for days and nothing seems to be covering it for me? Would appreciate any help, Regards [import]uid: 93704 topic_id: 29370 reply_id: 329370[/import]

To get a character to walk where you want is possible, but you really need to break down the problem and solve it one code step at a time.

For example, if you have a tilemap underneath (so the player can’t walk in a straight line to where you tap), in some ways it can be easier to move but there is some specific collision code you would have to write.

From a simplest form you can use transition.to() to have your character walk in a straight line to where you want to go;

transition.to(character, { x=event.x, y=event.y, time=500})

But that ignores all sorts of things, like what if the character is already moving, are they active, and so on.

As a rough example of how my current movement code works, I need to:

  1. Check if the tap point is far enough away on X or Y to start movement
  2. Determine the best direction to move (horizontal/vertical) and second best if that fails.
  3. Check collision to make sure you can take the first step.
  4. Check for another character there first to make sure you can step there.
  5. Check if the character is active.

You then put all of that into a function that is called whenever you tap, so it can run through the checklist and decide whether movement is allowed. (The physics module simplifies some of this, I imagine, but it’s still up to you to write code on how your character should behave.) [import]uid: 41884 topic_id: 29370 reply_id: 118040[/import]

Sorry to intrude on your thread, but does this sound familiar to you:

“lucky optimus goons” ? [import]uid: 77199 topic_id: 29370 reply_id: 118041[/import]

Richard thank you for these great tips, I guess I’ll have to put my thinking cap on and work through the rules as advised, cheers [import]uid: 93704 topic_id: 29370 reply_id: 118047[/import]

hi hatethinkingofnames

Sorry, what is “lucky optimus goons” ? Is it a game I should check the source code of or something? [import]uid: 93704 topic_id: 29370 reply_id: 118048[/import]