A
assassin7
Guest
Hello,
I am having issues with this platformer I am working on.
Code is below but basically. I am having troubles with the player character getting stuck on the side of the platform or I get the issues as shown in the attached GIF image. I have been troubleshooting it for 3 days and havent made any lead way at all. I am still working on the sprites but using place holders for now.
But I really need help fixing this issues
/////////////////////////////////////////////
Create Event:
////////////////////////////////////////////
hsp = 0;
vsp = 0;
jump_spd = 50//25;
max_spd = 10
//movespd = 10 // ladder speed
lad_spd = 10;
lad_vsp = 0
accel=0.5;
grav = 1;
on_ground = true;
In_air = false;
//facing=1;
enum state{
normal,
ladder,
hurt,
ok
}
current_state= state.normal;
hp = 5;
//ok_time = 3
ok_timer = 3
////////////////////////////////////////////
Step Event:
/////////////////////////////////////////////
/// @description Insert description here
// You can write your code in this editor
//Getting players input
#region inputs
key_right = keyboard_check(vk_right);
key_left = keyboard_check(vk_left);
key_jump = keyboard_check_pressed(vk_space);
key_up_dir = keyboard_check_direct(vk_up);
key_down_dir = keyboard_check_direct(vk_down);
key_jump_rel = keyboard_check_released(vk_space);
key_up = -keyboard_check(vk_up);
key_down = keyboard_check(vk_down);
#endregion
//checking if player is own ladder
if place_meeting(x,y,o_ladder)
{
if (key_up_dir || key_down_dir)
{
current_state = state1.ladder1;
}
}
//Checking states when player transitions between sprites and perform different actions
#region State machine
switch(current_state)
{
case state1.normal1:
image_speed = 1;
// Check if player is On Ground or In Air
if vsp == 0
{
on_ground = true;
In_air = false
}
else
{
on_ground = false;
In_air = true
}
////////////////////////////////
Getting players movements horizontally
/////////////////////////////////
#region Movement
if (hsp != 0)
{
image_xscale = sign(hsp);
}
#region Horizontal Movements
//changing left or right
if (key_right && key_left)
{
hsp = 0;
}
if(key_right or key_left)
{
hsp += (key_right - key_left) * accel
hsp = clamp(hsp, -max_spd, max_spd)
}
else
{
scr_friction(accel);
}
scr_collision(o_solid);
//scr_collision(o_oneway_plat1)
#endregion
/////////////////////////////////////
Players vertical movements
//////////////////////////////////////
#region Jumping
if !place_meeting(x,y + 1,o_solid)
{
vsp += grav;
if key_jump_rel && vsp < -20
{
vsp = -15;
}
}
else
{
vsp = 0
if (key_jump)
{
vsp = -jump_spd; // applies the jump speed
}
}
#endregion
#endregion
#region Animation normal state
//animations changes sprites for player
if (on_ground)
{
In_air = false;
if(hsp == 0)
{
sprite_index = spr_p
}
if (hsp !=0)
{
sprite_index = spr_p;
}
}
else
{
In_air = true;
}
//jumping and landing animation
if (In_air)
{
on_ground = false;
if (vsp < 0)
{
sprite_index= spr_p;
}
if (vsp > 0)
{
sprite_index= spr_p;
}
}
else
{
on_ground = true;
}
#endregion
break;
#region Ladder State
case state1.ladder1:
sprite_index = spr_p;
#region ladder movement
#region Vertical Movements
//changing left or right
var v_move = key_down + key_up;
vsp = lad_spd * v_move;
//grav = 0
if v_move == 0
{
image_speed = 0;
}
if v_move != 0
{
image_speed = 1;
}
y+=vsp
//scr_collision(o_ladder);
#endregion
#endregion
#region cancel climb
if key_jump
{
current_state= state1.normal1;
}
if !place_meeting(x,y,o_ladder)
{
current_state= state1.normal1;
}
#endregion
//////////////////////////////////////////////////////////////
Collision Scriptscr_collision)
/////////////////////////////////////////////////////////////
#region collision
var collison_obj = argument0
//vsp += grav;
// Horizontal
if place_meeting(x+hsp,y,collison_obj)
{
while (!place_meeting(x+round(sign(hsp)),y,collison_obj))
{
x += sign(hsp);
}
hsp = 0;
}
x+=hsp
//vertical
if place_meeting(x,y+vsp,collison_obj)
{
while (!place_meeting(x,y+sign(vsp),collison_obj))
{
y += sign(vsp)
}
vsp = 0;
}
y+=vsp
#endregion
//////////////////////////////////////
friction script : scr_friction
////////////////////////////////////
var amount = argument0;
if(hsp != 0)
{
if(abs(hsp) - amount > 0)
{
hsp -= amount * image_xscale;
}
else
{
hsp = 0;
}
}
I am having issues with this platformer I am working on.
Code is below but basically. I am having troubles with the player character getting stuck on the side of the platform or I get the issues as shown in the attached GIF image. I have been troubleshooting it for 3 days and havent made any lead way at all. I am still working on the sprites but using place holders for now.
But I really need help fixing this issues
/////////////////////////////////////////////
Create Event:
////////////////////////////////////////////
hsp = 0;
vsp = 0;
jump_spd = 50//25;
max_spd = 10
//movespd = 10 // ladder speed
lad_spd = 10;
lad_vsp = 0
accel=0.5;
grav = 1;
on_ground = true;
In_air = false;
//facing=1;
enum state{
normal,
ladder,
hurt,
ok
}
current_state= state.normal;
hp = 5;
//ok_time = 3
ok_timer = 3
////////////////////////////////////////////
Step Event:
/////////////////////////////////////////////
/// @description Insert description here
// You can write your code in this editor
//Getting players input
#region inputs
key_right = keyboard_check(vk_right);
key_left = keyboard_check(vk_left);
key_jump = keyboard_check_pressed(vk_space);
key_up_dir = keyboard_check_direct(vk_up);
key_down_dir = keyboard_check_direct(vk_down);
key_jump_rel = keyboard_check_released(vk_space);
key_up = -keyboard_check(vk_up);
key_down = keyboard_check(vk_down);
#endregion
//checking if player is own ladder
if place_meeting(x,y,o_ladder)
{
if (key_up_dir || key_down_dir)
{
current_state = state1.ladder1;
}
}
//Checking states when player transitions between sprites and perform different actions
#region State machine
switch(current_state)
{
case state1.normal1:
image_speed = 1;
// Check if player is On Ground or In Air
if vsp == 0
{
on_ground = true;
In_air = false
}
else
{
on_ground = false;
In_air = true
}
////////////////////////////////
Getting players movements horizontally
/////////////////////////////////
#region Movement
if (hsp != 0)
{
image_xscale = sign(hsp);
}
#region Horizontal Movements
//changing left or right
if (key_right && key_left)
{
hsp = 0;
}
if(key_right or key_left)
{
hsp += (key_right - key_left) * accel
hsp = clamp(hsp, -max_spd, max_spd)
}
else
{
scr_friction(accel);
}
scr_collision(o_solid);
//scr_collision(o_oneway_plat1)
#endregion
/////////////////////////////////////
Players vertical movements
//////////////////////////////////////
#region Jumping
if !place_meeting(x,y + 1,o_solid)
{
vsp += grav;
if key_jump_rel && vsp < -20
{
vsp = -15;
}
}
else
{
vsp = 0
if (key_jump)
{
vsp = -jump_spd; // applies the jump speed
}
}
#endregion
#endregion
#region Animation normal state
//animations changes sprites for player
if (on_ground)
{
In_air = false;
if(hsp == 0)
{
sprite_index = spr_p
}
if (hsp !=0)
{
sprite_index = spr_p;
}
}
else
{
In_air = true;
}
//jumping and landing animation
if (In_air)
{
on_ground = false;
if (vsp < 0)
{
sprite_index= spr_p;
}
if (vsp > 0)
{
sprite_index= spr_p;
}
}
else
{
on_ground = true;
}
#endregion
break;
#region Ladder State
case state1.ladder1:
sprite_index = spr_p;
#region ladder movement
#region Vertical Movements
//changing left or right
var v_move = key_down + key_up;
vsp = lad_spd * v_move;
//grav = 0
if v_move == 0
{
image_speed = 0;
}
if v_move != 0
{
image_speed = 1;
}
y+=vsp
//scr_collision(o_ladder);
#endregion
#endregion
#region cancel climb
if key_jump
{
current_state= state1.normal1;
}
if !place_meeting(x,y,o_ladder)
{
current_state= state1.normal1;
}
#endregion
//////////////////////////////////////////////////////////////
Collision Scriptscr_collision)
/////////////////////////////////////////////////////////////
#region collision
var collison_obj = argument0
//vsp += grav;
// Horizontal
if place_meeting(x+hsp,y,collison_obj)
{
while (!place_meeting(x+round(sign(hsp)),y,collison_obj))
{
x += sign(hsp);
}
hsp = 0;
}
x+=hsp
//vertical
if place_meeting(x,y+vsp,collison_obj)
{
while (!place_meeting(x,y+sign(vsp),collison_obj))
{
y += sign(vsp)
}
vsp = 0;
}
y+=vsp
#endregion
//////////////////////////////////////
friction script : scr_friction
////////////////////////////////////
var amount = argument0;
if(hsp != 0)
{
if(abs(hsp) - amount > 0)
{
hsp -= amount * image_xscale;
}
else
{
hsp = 0;
}
}
Attachments
-
36.2 KB Views: 8
-
46.6 KB Views: 8