How to Move an object up and down with touch?

Get help using Construct 2

Post » Sun Oct 06, 2013 3:59 am

Hello,
I'm a doubt about touch. How do I touch up when an object make it move X px up and down when playing make him move X px down?



Can anyone help me?
B
24
S
4
G
2
Posts: 96
Reputation: 2,467

Post » Sun Oct 06, 2013 8:22 am

I don't know if i get your problem.
Buut I think you could do this

Every tick > set objects position to touch.x+*number* and touch.y+*number*

This will set the object where you touch but slightly lower(plus y) and slightly to Left(plus X)

Hope this helpsAustris2013-10-06 11:22:10
B
4
Posts: 21
Reputation: 273

Post » Sun Oct 06, 2013 10:41 am

Easiest way would be to install the most used third-party plugin MoveTo.

All you'd have to do is to compare touch.y with sprite.y and set MoveTo destination accordingly.

Another way is to cretae a custom movement that does exactly the same.

And yet another way is to create this movement in events by using lerp and dt to make the transition between SpriteOldY and SpriteDestination visible.
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Mon Oct 07, 2013 3:38 am

Thanks, guys.

I doing using the plugin "MoveTo". But it's strange, whenever he (the circle =P) moves to top or down he "walking to back", any idea how to fix this?



The .capx url (https://dl.dropboxusercontent.com/u/2064178/test01.capx)

Thank you again!moebios2013-10-07 03:42:01
B
24
S
4
G
2
Posts: 96
Reputation: 2,467

Post » Mon Oct 07, 2013 4:04 am

Use lerp :D
B
47
S
14
G
7
Posts: 603
Reputation: 8,141

Post » Mon Oct 07, 2013 4:10 am

I don't know what's lerp! @[email protected]
B
24
S
4
G
2
Posts: 96
Reputation: 2,467

Post » Mon Oct 07, 2013 7:03 am

So... I'm trying to use 'derp' now, but, I don't understanding their final parameter.
The circle don't move to a new position, he is "jumping" to a new position. How I can fix this? Somebody know?



Capx:https://dl.dropboxusercontent.com/u/2064178/test02.capx

Thank you    moebios2013-10-07 07:04:32
B
24
S
4
G
2
Posts: 96
Reputation: 2,467

Post » Mon Oct 07, 2013 7:48 am

LERP(start, end, alpha)

There is a tutorial on LERP in the tutorials section. It's a fantastic place to learn many of the in's and out of C2. Especially to help new users to get there feet running and best of all. it's immediatly there adn doesn't require any waiting for a reply.


Anyways, LERP
Start, this is the original start value of a number range.
End, this is the last value in the number range.
Alpha which is a 0.0 to 1.0 value. Represents the %0 to %100 of the two numbers. So here is a couple of examples.



50 = lerp(0, 100, 0.5)
440= lerp(200, 1000, 0.3) ie %30

However, often LERP is used for the fantastic use of acceleration to deceleration of movement over distance.

EveryTick
Player.Y = lerp(player.y, touch.y, 0.1)

This results that per tick the player will move 10% of the distance between the players current distance and the target distances. So the farther the player is away. the faster the players moves. However as the player get's closer the player will slow down do to the fact that %10 becomes smaller per tick.


B
90
S
18
G
9
Posts: 2,455
Reputation: 15,028


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 41 guests