best approach to move a character for horizontal scoller

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
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
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
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.
cheers
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
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?
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.
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