Global Movement Entity??? [SOLVED]

This forum is currently in read-only mode.
From the Asset Store
Globals 2.0
$3.60 USD
10% off
Globals 2.0 stores and group variables. You can also load and save data (variables) from/to JSON files.
  • I am trying to make grid-movement sidescroller. Player and enemies all use grid mevement behavior but with diferent settings... Beside of that Player can change direction of gravity, so same input can have diferent actions (vertical or horizontal, +1 grid size or -1 grid size), and some enemies can walk on wals. I can make each of this movements separatly, but I wonder if I can make something like one Global Movement Entity function, so that this function can be called from each object who have grid movement with different settings that are then sent to this function.

    If I include all moving entites in to family MovEnt, can I then do something like this:

    for enemies something like -

    Bad.X < Player.X --- set Bad.Value('Step') to 1

                     --- Call function "MoveHor"

    Player -

    Left Arrow is down --- set Player.Value('Step') to -1

                       --- Call function "MoveHor"

    ...and so on...

    On fuction "MoveHor" --- MovEnt: Move MoveEnt.Value('Step') horizontaly

    I cant access MoveEnt private variables in "move X steps horizontaly" field of MoveEnt grid movement behavior... Is there some other way to do something like this? (sorry for bad english)

  • Solved - MovEnt.Value('Step')

    I did not know that it can be entered manualy...

  • interesting question

    do your characters have the ability to jump?

    And if they do, Is the jump based on grid movement?

    If it is... Strange feeling

    Anyway here is what I would do... I'm actually working on some changing gravity stuff too so I already figured out some stuff like how to unify code for all direction.

    Basically I use some vector concept

    like in the basic direction you have

    Up : (0,-1)

    Down : (0,1)

    Left : (-1,0)

    Right : (0,1)

    as vector for each direction.

    if you have a character on a wall facing right, his up, left, down and right vector would be something like (1,0), (0,-1), (-1,0) and (1,0)

    etc.

    So the idea is to have 9 variables for each character (enemy or player).

    Only one is really important but the other are better for code readability

    so these variables would be :

    • direction (the most important one)
    • xT and yT (for the top vector)
    • xB and yB (for the bottom vector)
    • xR and yR (for the right vector)
    • xL and yL (for the left vector)

    the direction variable can have a value form 0 to 3 representing the 4 possibilities :

    • 0 on the ground
    • 1 on a wall facing right
    • 2 on the ceiling
    • 3 on a wall facing left).

    This way you can set each of your vector depending on this variable like this :

    Top

    xT = round(sin('direction'*90))

    yT = 0-round(cos('direction'*90))

    Right

    xR = round(cos('direction'*90))

    yR = 0-round(sin('direction'*90))

    Bottom

    xB= 0-xT

    yB= 0-yT

    Left

    xL= 0-xR

    yL= 0-yR

    and then if you want to move a character to his right you just have to :

    + MouseKeyboard: On player 1 pressed "Move Right"

    -> Character: Set X to 'xR' * 'speed' * TimeDelta

    -> Character: Set Y to 'yR' * 'speed' * TimeDelta

    Now for the grid movement :

    You have to set the size of your grid cell in a global variable

    I will name it global('cellSize')

    you also need a variable that will carry the direction of your movement during the interpolation between one cell to the other

    I propose 'xMove' and 'yMove' this way we will also use the aformentionned vector.

    And to be accurate we will store the coordinate of the character before the interpolation in 'xStart' and 'yStart'

    Then you wil have something like that :

    + MouseKeyboard: On player 1 pressed "Move Right"

    -> Character: Set 'xStart' to .X

    -> Character: Set 'yStart' to .Y

    -> Character: Set 'xMove' to 'xR'

    -> Character: Set 'yMove' to 'yR'

    now 'xMove' and 'yMove' carries the direction of the interpolation.

    while 'xStart' and 'yStart' keep the origin safe.

    Now you just have to do :

    + Character: Value 'xMove' Greater than 0

    + System: Abs(Character('xStart')-Sprite.X) Lower than global('cellSize')

    -> Character: set X to X+'speed'*'xMove'*Timedelta

    + else

    -> Character: set X to 'xStart'+'xMove'*global('cellSize')

    -> Character: set 'xMove' to 0

    + Character: Value 'yMove' Greater than 0

    + System: Abs(Character('yStart')-Sprite.Y) Lower than global('cellSize')

    -> Character: set Y to Y+'speed'*'yMove'*Timedelta

    + else

    -> Character: set Y to 'yStart'+'yMove'*global('cellSize')

    -> Character: set 'yMove' to 0

    And that should do.

    So to sum up, you just have to put whatever direction you want in 'xMove' and 'yMove' to make your character moves

    ah and the 'speed' variable is how many pixel/second you want it to move.

  • Man, this is beautifull!!!

    Right from the start I gave up custom grid movement, because Im not so good constructor, but with this it's there. Then I try to figure out one function for all gravity directions for days and eventualy I gave up that too, and I do it manualy - I needed to see will the game concept work. Thanks again!

    Yes characters can jump, and each of them use Grid Movement Behavior. They can jump up, lef or right. Jump Up - 2 cells up and different animation is playing, jump from place left/right 4 cels horizontaly, jump from sprint 8 cels horizontaly (they dont fall if there is no ground until movement is finished). Think of Prince of Persia or Flashback style of movement. Character can exist only at one of predefined positions at time and its predefined set of states, and cant change that state while curent state does something, or can again in some of predefined conditions.

    If you are interested in some basic Flashback concept stuff you can find it here

    Thanks!!!

  • I follow your way of creating grid movement but there is some problem with it. After one step is over and xMove is set to 0 again, sprite is back at the begining, or few pixels ahead. I cant find what is causing problem. Here is cap

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Hey dude, did you figure this out, and is there any way of uploading it? Im new to making games and im trying to do the same thing but found nothing in the way of tutorials. Any help you can offer would be gratefully received.

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