How do I move from position A to B using touch positions?

0 favourites
  • 4 posts
From the Asset Store
With this template you will learn how to use the GooglePlay Games native plugin
  • Hi all,

    Basically I need to move the player from position A to position B (image).

    To achieve this I am comparing the Touch X position with player X position. I do the same with Y.

    Based on the results of the comparison, I move the player to the touch position regardless where it is.

    The problem is that if X is shorter than Y, it moves horizontally than it moves vertically but it never moves diagonally. The same happens when Y distance is shorter than X. (image on the left)

    I am trying to achieve (image on the right) without the chopping issues.

    Thanks,

  • global variable"cantouch" =0

    ->on touch set global variable "endx" to touch.x, "endy" to touch.y

    ->set global variable "canmove" to 1

    ->set global variable "cantouch" to 1

    ->wait distance(player.x,player.y, touch.x,touch.y)*your speed

    ->set global variable "cantouch" to 0

    ->set global variable "canmove" to 0

    global variable "canmove" =1

    ->player set position to lerp(self.x,endx,your speed*dt) lerp(self.y,endy,your speed*dt)

    Or something like that....

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • newt It worked great!

    However, I didn't need to use both canmove and cantouch, just one.

    Also, I didn't understand the line ->wait distance(player.x,player.y, touch.x,touch.y)*your speed

    What is it?

    Thanks,

  • The wait tells it when to stop, and when using cantouch, tells it when it can touch again.

    You don't have to use it, but it will keep lerping if you don't change the variable at some point.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)