Issues with key movement

bebofirebebofire Member Posts: 2
edited November -1 in Working with GS (Mac)
Hi, I'm attempting to make a game with a 'classic' feel, without diagonal movement... I noticed that keys don't register as "up" unless they've first been pressed down, and in my code I instructed the "move right" and "move left" rules to only work if the up and down keys register as "up", so basically this translates into when I preview the scene, I first have to move my actor up and then down before I can move it side to side at all. Is there any way around this? Thanks.

Also, I was wondering if there's a way to make a sort of "uneven" movement (think: the way your character moves in pokemon), where essentially the character moves in a staggered fashion in defined squares of placement, is there a way to do this?

Thanks,
Bebofire

Comments

  • CodeMonkeyCodeMonkey Head Chef, Member, PRO Posts: 1,803
    Hi bebofire.

    I don't think I fully understand what you want for game play purposes for the movement when the key is "up". If you want them to start moving as soon as the game starts, you can just give them the Change Velocity behavior not inside any rules. Keep your current "up" rules. OR you can make the rules "down" and put your functionality in the Otherwise clause. I think that should work.

    I'm also not aware of the staggered movement you speak of. Do you mean like in the way on a checkers board where you jump from square to square? If so, then I would using Change Attribute on the position of the actor and adding a set amount depending on which direction you choose. I'll post a wiki and game demo on it soon.

    Hope that helps
  • bebofirebebofire Member Posts: 2
    Well... not exactly my problem.
    Essentially I was trying to eliminate any possibility of diagonal movement. In the "move left" and "move right" rules I put three conditions: that key [left or right] is "down", AND the up and down keys have to be "up".

    This works fine, but unfortunately when I run my game I have to first move up, then down, in order to make the up and down keys register as "up" when I'm not pressing them.

    By the staggered movement I basically mean like the movement works in pokemon games, I don't really have a better way to describe it, but when you let go of a directional key the actor will continue to move until he is fully into the next invisible "square" in the game. This only allows the actor to be in a limited number of essentially pre-set squares in the game (although there are a lot of them, because the screen is something like a 15 x 10 grid of squares). This looks good because bushes can simply take up a whole "square" and trees can take up four "squares", for instance.
  • lordsprinkleslordsprinkles Member Posts: 19
    Hey bebofire,

    If you want to eliminate any diagonal movement you can use the Move behavior and set the attribute to 'stacked' instead of 'additive'. Then you don't have to use all those extra rules that seem to be causing your movement bug when the game loads.

    As for the character continuing movement after letting up on the key, maybe you can use an 'accelerate' behavior that would keep the character moving in that direction even though the key isn't being pressed anymore.
  • ZourathZourath Member Posts: 16
    Try this for staggered movement. Make two new attributes in the moving actor, they can be named anything, but I will call them LocX and LocY. When the actor is created, set LocX equal to the actor's horizontal location, and LocY equal to the actor's vertical location. When you press a direction, make it move as normal. have two rules running constantly with the following settings:

    Conditions: horizontal location = LocX+X(X = however big the map grid sections are)
    horizontal location = LocX-X
    When any conditions are valid:
    Change Attribute: Linear Velocity.X = 0
    Change Attribute: LocX = horizontal location

    Conditions: vertical location = LocY+X(X = however big the map grid sections are)
    vertical location = LocY-X
    When any conditions are valid:
    Change Attribute: Linear Velocity.Y = 0
    Change Attribute: LocY = vertical location

    This will only work if the object's speed in pixels is divisible into X, so it will be guess and check to get a speed that works.
Sign In or Register to comment.