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

0 favourites
  • 7 posts
From the Asset Store
This is a code so you can see the same skin on all screens (peers). Each peer gets a skin, in addition to 4 directions t
  • 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!

  • 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.

  • 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

  • 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 , 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.. ;)

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks both of you randomly ! 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.

  • Hey baokinh ,

    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:

    dropbox.com/s/58mxrdak8cxe9e3/TappingSpeed.capx

  • Wow thanks randomly for the project and the comments that's super nice from you!

    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

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