How do I make my hero move depending of the speed of touch?

Get help using Construct 2

Post » Wed Oct 05, 2016 10:01 am

Hi!

I have a little character facing right and runing on the left side of the screen and the ground is sliding under his running feet at constant speed when I don't touch anything.

This is what I need : my character has to accelerate more and more, depending of the speed I tap a button. If I tap 10 times per second he should reach the middle of the screen and if I can tap even faster he could reach the right side of the screen. The ground would slide faster too.
If I tap slower he should loses ground or if I stop tapping he will go back to his initial position on the left.
What is the best way to do that?

Thanks for any help!
B
3
G
2
Posts: 6
Reputation: 1,085

Post » Wed Oct 05, 2016 11:46 am

@baokinh

Well, there are some possible ways you could go.
The easiest one would be to have a global or instance variable, e.g. "speed", initial value = 0
Your character would be moved horizontally based on the value of "speed".

In detail, this means:
- each time you tap, the value gets increased by a specific (and small) amount.
- every x seconds or every tick (depending on your preference), the character gets moved +speed pixels on the horizontal axis
(the faster you tap, the further the character goes)
- every x seconds or every tick (again, depending on your preference), the "speed"-value gets decreased by a specific amount, causing the character to go backwards when the value is under zero.
(To prevent the character going off-screen, you would have to clamp his x coordinate)

The exact amounts and timings depend on your likings.
This is the basic principle, I would go with. It seems the simplest to me.

_________________

If I wasn't clear enough, I can try to create an example project for you.
"We can't solve problems by using the same kind of thinking we used when we created them."
- Albert Einstein
B
27
S
11
G
8
Posts: 528
Reputation: 7,091

Post » Wed Oct 05, 2016 2:05 pm

If you aren't already using a movement type I would use lerp()

If you aren't familiar with lerp() it is actually pretty simple. lerp(position1, position2, progress) -> progress should be between 0 and 1 where 0 = position 1 and 1 = position 2.

So I would have an instance variable of progress and speed. Then Left and Right I use below are the farthest left you want the player to go and the farthest right you want the player to go.

Events would be:
Every tick -> Add Speed to Progress; set position to lerp(Left, Right, progress)
--Progress <= 0 then progress = 0
--Progress >= 1 then progress = 1
--Speed > min speed then reduce speed by ?

Every button press
--Speed < max speed then increase speed by ?

Your speed is going to be very small because a speed of 1 would move from left to right side of screen in one tick. Even a speed of 0.1 is too high. Maybe have max speed be 0.02 and min speed be -0.02; increase on button press 0.001 and decrease every tick 0.0001. ...those are just educated guesses though from math in my head, so may be way off.

If you are confused could throw together a capx but probably not anytime to soon... hope this helps
ImageImageImage
B
40
S
23
G
11
Posts: 498
Reputation: 10,062

Post » Wed Oct 05, 2016 2:30 pm

I'll see whether I can create a capx at some point including the two methods.
Though there is this thing calles...private life, which keeps me from doing it.
Goddamnit.
Same here as for @badmoodtyler, I'll see when I have time, I'll go for it.

But maybe those two solutions are enough initial thrust for you to launch your mind and get your project done.. ;)
"We can't solve problems by using the same kind of thinking we used when we created them."
- Albert Einstein
B
27
S
11
G
8
Posts: 528
Reputation: 7,091

Post » Wed Oct 05, 2016 4:26 pm

Thanks both of you @randomly @badmoodtyler ! I really apreciate your help.
I'm going to try by myself today to see if I manage to get something workable, can't wait to test what you both explain. This is the initial direction I needed.
I will get back to you in case of emergency! :)

Have a nice day Gentlemen.
B
3
G
2
Posts: 6
Reputation: 1,085

Post » Thu Oct 06, 2016 1:18 pm

Hey @baokinh @badmoodtyler,

I assembled a little capx over night in case you get stuck.
It's nor perfect nor complete but I guess it showcases the two version pretty good.
Have fun.

Download:
https://www.dropbox.com/s/58mxrdak8cxe9e3/TappingSpeed.capx?dl=1
"We can't solve problems by using the same kind of thinking we used when we created them."
- Albert Einstein
B
27
S
11
G
8
Posts: 528
Reputation: 7,091

Post » Thu Oct 06, 2016 2:41 pm

Wow thanks @randomly for the project and the comments that's super nice from you! :D
I'm going to get my head into your capx and try to understand because I can't get mine to work...

The "notimportant" group is really the final art touch! hehe

Thanks a Lot for your time!! I get back in
B
3
G
2
Posts: 6
Reputation: 1,085


Return to How do I....?

Who is online

Users browsing this forum: vutankhoa2015 and 21 guests