GM:S 1.4 RPG Movement

Discussion in 'Programming' started by PeterPeashooter, Dec 7, 2018.

  1. PeterPeashooter

    PeterPeashooter Member

    Joined:
    Dec 7, 2018
    Posts:
    1
    Sorry, I’m new to coding and so this question is basic. What is the best way to make an RPG character move?
    Ideally it needs to
    - move with arrow keys smoothly
    - change sprite based on direction
    - if it stops, it has to stop at the “idle position” (like when a chapter stops, it doesn’t just stop with its legs in the air)
    - Run maybe? (Holding shift or some sort of running button makes character move a bit faster)
    - collide with a wall which stops the character’s movement
    - perhaps the character could be able to interact with something and when you press a button (like ‘Z’) it makes dialogue

    I would really appreciate it if someone could help me out because I looked literally everywhere and all of them ended up weird. I can accept really complex code as long as I know how it works w/ explanations.
    Thanks for reading,
    peter
     
  2. Gunner

    Gunner Member

    Joined:
    Mar 4, 2018
    Posts:
    23
    Why don't you go back here with all the things that you think are weird and maybe we can help point it out for you instead?
     
  3. Pyxus

    Pyxus Member

    Joined:
    Nov 6, 2016
    Posts:
    183
    You're asking the wrong question, forget about the "best way" how do you want the rpg character to move? 8-Directional movement, maybe snap to some sort of grid, perhaps the rpg isn't top down and the player just moves left and right? Also, you may not realize it since you're still learning but you're asking for help with a lot more than just movement. Movement can be summed up as adding to an object's x/y values. if (right) x+=5. Collisions, dialogue, character interactions, and sprite behavior are separate affairs. I'd recommend starting with collisions since that sort of goes hand in hand with the movement. This video is great for understanding the concept, it doesn't actually show the code but a simple search will net you results on a ton of collision-related tutorials.
     
  4. OblivionSkull21

    OblivionSkull21 Member

    Joined:
    Sep 26, 2017
    Posts:
    178



    These two videos should help you. What you are asking for is actually a lot more than just player movement. Initiating dialogue, for example, is quite complicated.

    I'll just help you with the movement, running, sprite animations, and collision with walls.

    For example, controlling the player's idle sprite involves image_speed and image_index. Image index basically refers to the corresponding frame in the sprite's animation.
    So if your sprite has 3 frames with the first frame being the idle frame, you would set the image_index = 0 (in Game Maker, the first frame is 0, the second is 1, etc.) and then set the image_speed = 0 (so that the sprite stops animating)

    For a basic 4-direction movement without diagonal sprites, it shouldn't be too hard.

    In your player object, you should have the following:

    Create Event:
    Code:
    run = 0;
    image_index = 0; //first frame  or the idle animation of the player
    image_speed = 0; //character isn't moving
    Step Event:

    Code:
    if keyboard_check_pressed(vk_right) { // the right key
    x += 4 + run; //change this to however fast you want the player to move
    sprite_index = spr_player_right; //each direction should have its own sprite with its own frames, so you should make four sprites (player_up, player_down, player_right, player_left. sprite_index allows you to switch the sprite being displayed inside the player object.
    image_speed = .25; //change this to how fast you want the player to animate
    }
    
    if keyboard_check_pressed(vk_left){ //left key
    x -= 4 + run;
    sprite_index = spr_player_left;
    image_speed = .25;
    }
    
    if keyboard_check_pressed(vk_up) { //up key
    y -= 4 + run; //y actually counts down on Game Maker's coordinates, not up.
    sprite_index = spr_player_up;
    image_speed = .25;
    }
    
    if keyboard_check_pressed(vk_down){ //down key
    y += 4 + run;
    sprite_index = spr_player_down;
    image_speed = .25;
    }
    
    else{ //you aren't pressing any buttons, so the sprite should be idle
    image_index = 0;
    image_speed = 0;
    }
    
    if keyboard_check_pressed(vk_shift){//run key
    run = 4; //change this to the speed you want to be when running
    image_speed = .5; //the player should animate twice as fast when running??
    }
    As for the object's initial sprite, you should use which ever sprite is the direction the player starts the game in (Ex. down/front)

    If you're using physics, then you should change the x's to phy_position_x and the y's to phy_position_y.

    Collision with a wall should probably be done using physics, so you should follow the directions above. Don't forget to set your room to physics world and both your objects to physics object.

    For wall collision, add a collision event with the obj_wall in your player object:
    Code:
    image_index = 0;
    image_speed = 0;
    
    You also need to set up the collision boxes for both objects so that they actually have something to collide with.

    Again, this is actually a lot to ask so I suggest watching the videos above for more information.
     
    Last edited: Dec 7, 2018
  5. Evan Malinowski

    Evan Malinowski Member

    Joined:
    Apr 17, 2018
    Posts:
    207
    @GMWolf Has a good video on this aswell but its more like the Final Fantasy V grid locked movement

     
    GMWolf and Pyxus like this.
  6. Pyxus

    Pyxus Member

    Joined:
    Nov 6, 2016
    Posts:
    183
    Why would you bother using the physics engine for rpg collisions? I guess it would simplify collisions but it really just seems superfluous.
     
  7. OblivionSkull21

    OblivionSkull21 Member

    Joined:
    Sep 26, 2017
    Posts:
    178
    It's all just personal preference really. The physics engine is good for games that have precise collisions. We aren't entirely sure what the OP is wanting in terms of an RPG as there are several different genres where the physics engine could definitely help depending on the game mechanics. For example, if it's a bullet hell RPG, then physics would definitely help.

    Just thought to let the OP know that they should change the variables if this is what they choose.
     
  8. TheouAegis

    TheouAegis Member

    Joined:
    Jul 3, 2016
    Posts:
    5,647
    Why do you need it to be "idle" when it's standing still? That didn't matter to the guys that made Action 52, one of the most famous games ever made!
     
  9. OblivionSkull21

    OblivionSkull21 Member

    Joined:
    Sep 26, 2017
    Posts:
    178
    This is true. Perhaps you (the OP) could have the player "bounce" up in down while he's not moving so that he isn't completely stagnant.
     
  10. RefresherTowel

    RefresherTowel Member

    Joined:
    Jul 13, 2016
    Posts:
    661
    Using the physics engine as a basis for an RPG was the silliest thing heartbeast has done. Normally he's pretty good, but that...urghhh.
     
    Pyxus likes this.

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice