Isometric 2.5D platformer moving problems

S

shostifrosty

Guest
Hello there!

My name is Alice and I am new in the forum. ^____^ First of all I would like to thank you all for having such a nice forum with so many guidelines and threads helping people – that were very helpful for me as well, though now I am stuck (this is why I am posting here).

The point is that I was following some tutorials for an isometric platformer I am trying to develop, but I was struggling for several weeks already just trying to make the player moving around and jump using z, and the things are just not working at all.

The main problems are:

1) The animations won't work when I move around, just the first frame of the animation is showing

2) When the character jumps, the main image just stays there, and also after the second jump, it flies away Buzz-lightyear-style to infinity and beyond

3) I can't make the character jump over the objects because it works partially only (it can jump over the object and get stuck, or if it can be over the object, it will never come back to the ground again)

I will leave the code:

Code:
CREATE:

main_sprite = Ichigo_frente_drcha;

state = "idle"

z = 0
z_speed = 0
z_gravity = 0.2
z_bottom = 0

STEP

// Esto es para la profundidad

depth = -y;

h_spd = 0;
v_spd = 0;

/// Mover abajo
if (keyboard_check(vk_down)) && (place_free (h_spd+2, v_spd+1))
{
h_spd += 2;
v_spd += 1;
main_sprite = andando_frente_derecha;
image_speed = 0.1;


}

//Mover arriba
if (keyboard_check(vk_up)) && (place_free (h_spd-2, v_spd-1))
{
h_spd -= 2;
v_spd -= 1;
main_sprite = Ichigo_espalda_izquierda
image_speed = 0.1;
}

// Mover izquierda
if (keyboard_check(vk_left)) && (place_free (h_spd-2, v_spd+1))
{
h_spd -= 2;
v_spd += 1;
main_sprite = Ichigo_frente_izquierda
image_speed = 0.1;
}

// Mover derecha
if (keyboard_check(vk_right)) && (place_free (h_spd+2, v_spd-1))
{
h_spd += 2;
v_spd -= 1;
main_sprite = Ichigo_espalda_derecha;
image_speed = 0.1;
}

//Jump

jump = keyboard_check_pressed (vk_space);

switch (state)
    {
    case "idle":
        if (jump)
            {
            z_speed = 4;
            state = "jump"
            }
     
        if !(place_meeting(x,y,object5))  &&  z_bottom  !=0
            {
            state= "jump"
            z_bottom= 0;
            }
 
        break;
 
    case "jump":
    z  -=  z_speed
 
        if z < z_bottom
 
        {
        z_speed -= z_gravity;
        }
 
        if z >= z_bottom
 
        {
        z = 0;
        z_gravity = 0
        state = "idle";
        }
 
        break;
 
    }


var i, move_check;

 
for (i = abs(h_spd); i > 0; i -= 1;)
    {
 
    move_check = sign(h_spd) * i;
    inst = instance_place ( x + move_check, y, object5);
 
 
    if !place_meeting(x + move_check, y, object5) || z <= inst.z {x += move_check;break;}
 
 
    }
 
for (i = abs(v_spd); i > 0; i -= 1;)
    {
    move_check = sign(v_spd) * i;
 
    inst = instance_place(x, y + move_check, object5)
 
    if !place_meeting(x, y + move_check, object5)|| z <= inst.z {y += move_check; break;}

 
    }


DRAW

draw_sprite(main_sprite,  0, x, y + z);

if (state == "jump") draw_sprite (main_sprite, 0,x,y + z_bottom);

My version of GM is 1.4.1567


Any help will be much appreciated, for I've been struggling with this for sooo looooong with no results, and I really don't know what to do >-<

P.S: I know the code should be hilarious in the way that I mixed different tutorials and some things probably don't make any sense. I apologise for it in advance. I am no programmer – but a composer and an artist – and I did what I could xD


Thanks and see ya!
 
Last edited by a moderator:

Yal

🐧 *penguin noises*
GMC Elder
If you're having an isometric platformer, you probably should actually have three movement variables: x, y and z speeds. So x_spd, y_spd and z_spd instead of h_spd and v_spd. I think the main reason stuff doesn't work is because you're converting variables in tons of places, and it's easy to mess up. Basically, this is a three-dimensional problem, so trying to squeeze it into a two-dimensional framework just won't work. Your vertical position due to moving along the y axis is a different thing from your vertical position due to jumping/falling.

For x and y, it's a pretty simple thing:
Code:
//(x speed example)
if left button pressed:
  set x-speed to negative
else if right button pressed:
  set x-speed to positive
else
  set x-speed to zero

if(x speed not equals zero){
  if (no obstacle at x + x-speed){
    x += x-speed
  }
  else{
    xspeed = 0
  }
}
For z, it's a bit more complicated:
Code:
if thing under my feet:
  z-speed = 0
else:
  z-speed = min(terminal velocity, z-speed + gravity)

if(no obstacle at z + zspeed at current x, y){
  z += z-speed
}
else{
  zspeed = 0
  if was jumping: return to ground state
}
Also, I'd recommend actually naming your objects so you can quickly tell them apart later :p


EDIT: if it wasn't obvious, that stuff above is pseudocode, (aka explanations in code form) so it's not gonna work if you copypaste it :p
 
S

Silver_Mantis

Guest
1) The animations won't work when I move around, just the first frame of the animation is showing
Welcome to the community Alice!

So I see you're having some issues with your animations as well.
I think this is because you aren't setting any sprite_index.

Now from what I can tell, is that this code is within your player object correct?
The way you change your sprites is like this:
Code:
/// Mover abajo
if (keyboard_check(vk_down)) && (place_free (h_spd+2, v_spd+1))
{
h_spd += 2;
v_spd += 1;
sprite_index = andando_frente_derecha;
image_speed = 0.1;
}
You see sprite_index controls what sprite your object is using. It's not a variable you can just create. ;)

So also your Create Event will look like this:
Code:
sprite_index = Ichigo_frente_drcha;
 
Top