Drawinablank
Member
Hi. I hope everyone is enjoying the holiday season.
I have been working on a platform game for some time now and I came across an issue. When jumping and attacking I noticed that the character would stop it's horizontal movement and just drop. I noticed this would also happen when my enemy character would get hit in mid air. Basically the instance_change command would stall horizontal speed.
I don't know if this is normal programming or typical of all builds of game maker but I found a way around it and actually used this fact to make an effective mechanic. I just want to see if anyone has found a more effective way of dealing with the issue than I have. If so or if there are problems or points of contention please let me know but with that said I think I have found something.
Ok so I have some scripts set up to catalog movement variables and such. Also to note I am not using a FMS for these player related items. I am going to use an Enum and FMS for the enemies if it the most effective way.
sc_constants
/// Initialize variables
grav = 1;
spd = 4;
hspd = 0;
vspd = 0;
jspd = -12;
I have standard issue vertical and horizontal collision, movement and inputs scripts and the like (see below). Then I did this for the attack script.
sc_plattack
______________________________________________________________________________
///Attack hitbox
#region
var key_attack = keyboard_check_pressed(vk_shift);
sprite_index = splayat;
image_speed = 4;
if (key_attack)
{
sprite_index = splayat;
if(sprite_index = splayat) && (image_index >= 1) || (image_index <= 3)
{
sc_athitbox()
}
}
if (vspd = 0) && (key_attack)
{
sc_obathitbox() see below
}
#endregion
______________________________________________________________________________
sc_athitbox()
///only changes to character attacking sprite
#region
if(sprite_index = splayat) && (image_index >= 1) || (image_index <= 3)
{
with (instance_create_layer(x,y,"Melee",par_playatbox))
{
image_speed = 4;
image_xscale = other.image_xscale;
hspeed = hspeed * image_xscale;
}
}
#endregion
______________________________________________________________________________
sc_obathitbox()
///creates character attacking object if on ground only
instance_change(par_playat,true)
______________________________________________________________________________
So what I did is I took advantage of the instance change to make my player stop when attacking on the ground, beautiful. While the player is attacking in the air it does not change instance but only the animation cycle through the sprite_index = whatever statement and as such the character has a committed jump arc just as I has hoped and attacks just fine in the air. No mid air stalling. He jumps in the pointed direction cannot change direction and he rises and falls with no interruptions.
Now for my player object I have scripts for constants in the create event, input/movement and collision in the step.
sc_constant() see above
______________________________________________________________________________
sc_colli
standard issue collision code
#region
// Vertical collisions
if (place_meeting(x, y+vspd, obj_solid))
{
while (!place_meeting(x, y+sign(vspd), obj_solid))
{
y += sign(vspd);
}
vspd = 0;
}
//Move vertically
y += vspd;
// Horizontal collisions
if (place_meeting(x+hspd, y, obj_solid))
{
while (!place_meeting(x+sign(hspd), y, obj_solid))
{
x += sign(hspd);
}
hspd = 0;
}
//Move horizontally
x += hspd;
#endregion
______________________________________________________________________________
sc_move()
///Inputs
#region
var key_right = keyboard_check(vk_right);
var key_left = keyboard_check(vk_left);
var key_jump = keyboard_check_pressed(vk_space);
var grounded = place_meeting(x,y+1,obj_solid);
//React to inputs
if(vspd < 12)
{
vspd += grav;
//Jump
if (grounded)
{
var move = key_right - key_left;
hspd = move*spd;
vspd = key_jump * jspd;
if key_right
{
image_xscale = 1;
}
if key_left
{
image_xscale = -1;
}
}
}
#endregion
Basically that's it. Constants go in the Create event, movement and input scripts in the step and the attack script is under the key pressed event. Everything seems to work.
The reason I am posting this is because trying to find mechanics for fixed arc jumping and attacking is hard to find on this site. I am not saying that this is a failing of the site because to even word this issue properly for a search is a pain. In the end it is just one of those unavoidable things I guess. I hope that someone else can benefit from these findings. Please feel free to debate or discuss the approach to this issue.
Thank you and have a happy new year.
I have been working on a platform game for some time now and I came across an issue. When jumping and attacking I noticed that the character would stop it's horizontal movement and just drop. I noticed this would also happen when my enemy character would get hit in mid air. Basically the instance_change command would stall horizontal speed.
I don't know if this is normal programming or typical of all builds of game maker but I found a way around it and actually used this fact to make an effective mechanic. I just want to see if anyone has found a more effective way of dealing with the issue than I have. If so or if there are problems or points of contention please let me know but with that said I think I have found something.
Ok so I have some scripts set up to catalog movement variables and such. Also to note I am not using a FMS for these player related items. I am going to use an Enum and FMS for the enemies if it the most effective way.
sc_constants
/// Initialize variables
grav = 1;
spd = 4;
hspd = 0;
vspd = 0;
jspd = -12;
I have standard issue vertical and horizontal collision, movement and inputs scripts and the like (see below). Then I did this for the attack script.
sc_plattack
______________________________________________________________________________
///Attack hitbox
#region
var key_attack = keyboard_check_pressed(vk_shift);
sprite_index = splayat;
image_speed = 4;
if (key_attack)
{
sprite_index = splayat;
if(sprite_index = splayat) && (image_index >= 1) || (image_index <= 3)
{
sc_athitbox()
}
}
if (vspd = 0) && (key_attack)
{
sc_obathitbox() see below
}
#endregion
______________________________________________________________________________
sc_athitbox()
///only changes to character attacking sprite
#region
if(sprite_index = splayat) && (image_index >= 1) || (image_index <= 3)
{
with (instance_create_layer(x,y,"Melee",par_playatbox))
{
image_speed = 4;
image_xscale = other.image_xscale;
hspeed = hspeed * image_xscale;
}
}
#endregion
______________________________________________________________________________
sc_obathitbox()
///creates character attacking object if on ground only
instance_change(par_playat,true)
______________________________________________________________________________
So what I did is I took advantage of the instance change to make my player stop when attacking on the ground, beautiful. While the player is attacking in the air it does not change instance but only the animation cycle through the sprite_index = whatever statement and as such the character has a committed jump arc just as I has hoped and attacks just fine in the air. No mid air stalling. He jumps in the pointed direction cannot change direction and he rises and falls with no interruptions.
Now for my player object I have scripts for constants in the create event, input/movement and collision in the step.
sc_constant() see above
______________________________________________________________________________
sc_colli
standard issue collision code
#region
// Vertical collisions
if (place_meeting(x, y+vspd, obj_solid))
{
while (!place_meeting(x, y+sign(vspd), obj_solid))
{
y += sign(vspd);
}
vspd = 0;
}
//Move vertically
y += vspd;
// Horizontal collisions
if (place_meeting(x+hspd, y, obj_solid))
{
while (!place_meeting(x+sign(hspd), y, obj_solid))
{
x += sign(hspd);
}
hspd = 0;
}
//Move horizontally
x += hspd;
#endregion
______________________________________________________________________________
sc_move()
///Inputs
#region
var key_right = keyboard_check(vk_right);
var key_left = keyboard_check(vk_left);
var key_jump = keyboard_check_pressed(vk_space);
var grounded = place_meeting(x,y+1,obj_solid);
//React to inputs
if(vspd < 12)
{
vspd += grav;
//Jump
if (grounded)
{
var move = key_right - key_left;
hspd = move*spd;
vspd = key_jump * jspd;
if key_right
{
image_xscale = 1;
}
if key_left
{
image_xscale = -1;
}
}
}
#endregion
Basically that's it. Constants go in the Create event, movement and input scripts in the step and the attack script is under the key pressed event. Everything seems to work.
The reason I am posting this is because trying to find mechanics for fixed arc jumping and attacking is hard to find on this site. I am not saying that this is a failing of the site because to even word this issue properly for a search is a pain. In the end it is just one of those unavoidable things I guess. I hope that someone else can benefit from these findings. Please feel free to debate or discuss the approach to this issue.
Thank you and have a happy new year.