best approach to move a character for horizontal scoller

cekuhnencekuhnen Member Posts: 7
edited February 2012 in Working with GS (Mac)
I am trying to make a horizontal platformer and have an issue with moving the character left and right.

the code I use results in a sluggish movement - moving the character even when I do not press the left
or right key anymore.

all I want is the moment I stop pressing the character stops on the spot. Any code tip?
here is what I have sofar scripted for the move logic:

http://f.cl.ly/items/0E2g3p1o3f1m440C3z30/Screen Shot 2012-02-16 at 10.58.19 PM.png

Comments

  • JohnPapiomitisJohnPapiomitis Member Posts: 6,256
    edited February 2012
    Hey there,

    For your jump rule, dont use accelerate. Instead have when key up is down:
    -change attribute self motion linear velocity y to 400 (change the 400 to suite your jump height)

    For your move right rule have when key right is down:
    -change attribute self motion linear velocity x to 200 (change the 200 to adjust speed, just make sure its a postivie number)
    Then open up the otherwise section of that rule and have a change attribute behavior and change self motion linear velocity x to 0

    And for your move left rule have when key left is down:
    -change attribute self motion linear velocity x to -200 (again change the 200 to adjust your speed, just make sure its a negative number this time)
    Then open up that otherwise section of that rule as well and have a change attribute behavior changing self motion linear velocity x to 0


    Hope that helps
  • cekuhnencekuhnen Member Posts: 7
    Jo John

    ah this is interesting - it of course makes perfect sense to use the 0 speed argument in the otherwise section to make the character stop when not pressing the buttong anymore.

    One question I have is how to I make the character move left or right continuously when keeping the left or right arrow pressed.
  • JohnPapiomitisJohnPapiomitis Member Posts: 6,256
    If you set it up like i posted above it will move continuously when the keys are held down.

    cheers
  • cekuhnencekuhnen Member Posts: 7
    hi john

    i think i must do something wrong or gs is acting strange while pressing the arrow key only a single acceleration
    is done but not continiously executed.

    http://f.cl.ly/items/3m1d2o0l1D3P1S1X1l2r/speed.png

    here is the GS file as well
    http://cl.ly/0B310w1h1m3a131m0G3w
  • JohnPapiomitisJohnPapiomitis Member Posts: 6,256
    Sorry i think i misinterpreted what you were saying. When you press the key, it will change its velocity and will keep moving in that direction till you let go off the key. But its not a constant force threw out the whole key press. Is that what your wanting?
  • cekuhnencekuhnen Member Posts: 7
    lol lost in translation.

    what I would like to learn is this:

    If I press space bar my character jumps a bit and falls down again. I could keep spacebar pressed but he only gets moved up once.
    Cool would be to have a second spacebar press for a secondary jump.

    for left and right I can press my arrow left and right and the character moves left and right directly with the target speed also
    is not accelerating from 0 to finale speed - the character moves directly with that speed.

    The character continues moving with that speed as long as I keep the left and right arrow key pressed. The moment I do not press
    them the character stops spot on without slowing down and then stopping.

    Does make sense?
  • SlickZeroSlickZero Houston, TexasMember, Sous Chef Posts: 2,870
    Don't use accelerate for left and right movement either. Use the linear velocity, it's done the same way John showed you how to jump, but use linear velocity X instead of Y. And if you come across your character slowing down for no reason, use a rule that says - When linear velocity X is < 200 (use whatever number works for you) constrain attribute self linear velocity X to 200. That will force your actor to continuously move at the set velocity of 200.

    To do multiple jumps, you will need the rule to say what John showed you, but with one little added behavior. when key spacebar is pressed:
    -change attribute self motion linear velocity Y to self.position Y +400 (change the 400 to suite your jump height) Every time you press the space bar, it will jump 400 pixels higher than your current position, but if you keep pressing it over and over, you will fly off of the screen eventually.
  • cekuhnencekuhnen Member Posts: 7
    Slick

    this helped with maintaining the move speed:
    " When linear velocity X is < 200 (use whatever number works for you) constrain attribute self linear velocity X to 200. That will force your actor to continuously move at the set velocity of 200."

    Testing it I found out that to have a continuous left right move speed I could use use the constrain attribute for self.motion and for single jump impulse
    use the change attribute and let gravity force the character down again when the pulse energy is used up.

    Great ;)
Sign In or Register to comment.