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

Get help using Construct 2

Post » Wed Apr 29, 2015 8:17 pm

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.

Image


Thanks,
B
117
S
49
G
24
Posts: 401
Reputation: 22,282

Post » Wed Apr 29, 2015 8:47 pm

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....
Image ImageImage
B
169
S
50
G
169
Posts: 8,286
Reputation: 108,216

Post » Wed Apr 29, 2015 9:53 pm

@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,
B
117
S
49
G
24
Posts: 401
Reputation: 22,282

Post » Wed Apr 29, 2015 10:18 pm

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.
Image ImageImage
B
169
S
50
G
169
Posts: 8,286
Reputation: 108,216


Return to How do I....?

Who is online

Users browsing this forum: Lancifer and 10 guests