Actor behavior depending on how long key is pressed

KlasWKlasW Member Posts: 4
edited November -1 in Working with GS (Mac)
Hello everyone, this is my first post here at gamesalad so dont be mean, ;)

I am currently making a platform game were I want my player to have different acceleration in his jump depending on how long you press the key, is this possible? I have already tried with the timer but could not get it to work. Has someone done this in your own games an if that is the case how did you do it?

Thanks for reading! (My English is not so good, I am from Sweden)

Comments

  • DookiDooki Member Posts: 247
    Hey Klas,

    I am new to GS as well but I know you can do this. Take a look a the "Cannon" game under the New project tab, when you launch GS. You will see that the longer you hold down on the cannon the more power you get. You will also see a power bar to the side the shows you your power level.

    Also, I have posted a similar question called "Drag power." I have a cannon shooter game and I want to be able to tap and drag away from the cannon in order to control the power and direction of the shot. In your case, you could tap and drag in the direction of your jump and control how strong the jump will be.

    The people in the forum are VERY helpful!

    -Dooki
  • ChaserChaser Member Posts: 1,453
    Acceleration is a build up. The longer you hold the key the better chance it has to get to it's set acceleration. So if you set acc to 500 and hold it for a fraction of a second it never gets to 500. You hold it longer then the more potential it has to get to 500. For velocity the speed is instant then when let go it stops.

    Edit. You want a rule that when touch pressed change a game attribute interger to 1 and do an otherwise when released change to 0. Then on actor when game attribute is 1 then accelerate and when 0 do nothing
  • KlasWKlasW Member Posts: 4
    Hello again and thanks for the fast replies! I have tried to use the same method as used in the cannon game, but I could not really understand it. :( All I want to do is to have my player jumping longer when i hold down the jump key for some seconds, not to direct the jump with the mouse.
    I know that acceleration is a build up, but when I use the acceleration to jump as in the platformer example in GS you cant hold down the jump-key for a longer time to have a bigger jump. I still do not really get how you should do in order to be able to charge a jump, there must be someone else who have done this before?
  • ChaserChaser Member Posts: 1,453
    Aaahhhh charge a jump. so you hold the button or actor for a certain amount of time then let go and the actor jumps shorter or further depending on the "charge" or time held. Sorry haven't done that yet! You may want to set something up so that for every .2 seconds +1 to a game attribute called charge jump. So then on actor when game.charge = let's say 10 then for 2 seconds accelerate let's say 600. And so on when game.charge jump = 20 accelerate 600 for 4 seconds. You can play with the numbers
  • KlasWKlasW Member Posts: 4
    Ok, but post here again if you do do that, :P
  • ChaserChaser Member Posts: 1,453
    Sorry I did edit up above and noticed you responded before I posted. I'm not home so I'm going based on theory. May want to put another timer or attribute on actor that jumps so it waits to jump until your done holding the trigger
  • KlasWKlasW Member Posts: 4
    Thanks, I will try that!
  • tmoehletmoehle Member Posts: 30
    Hey Guys did you ever get this working?
  • TechnikTechnik Member Posts: 9
    Anyone? I need a hold longer accelerate longer thing for my platformer.
  • micksolomicksolo Member Posts: 264
    so you want to hold the button down, then when you release it jumps based on how long you held the button down? Or do you want, when the button is pressed, he jumps and the height / length of the jump is determined when touch is released?

    You could try something like this:

    Create a global Boolean attribute called TouchPressed
    Create a global real attribute called "AccelerationBoost"

    Whatever actor is controlling the touch to move your player, create this rule

    When Touch is pressed
    Change attribute TouchPressed = True
    Otherwise TouchPressed = false

    Timer
    Every 0.1 Seconds
    Change Attribute AccelerationBoost to AccelerationBoost + 0.1

    (This rule make it so when touch is pressed, AccelerationBoost will increase uniformly by 0.1 every 0.1 seconds)

    In your player actor make this rule
    When TouchPressed = True

    Change Velocity
    Speed = Game.AccelerationBoost
    Direction = (whatever direciton settings you have)

    So basically your player's speed will increase the longer you hold down the touch.

    Let me know if this works.
  • TechnikTechnik Member Posts: 9
    It's needing some tinkering but I think It'll work, thanks!
Sign In or Register to comment.