• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GML Help with angled player kickback mechanic.

J

JuiceBox

Guest
Hi everyone,

I'd like to start by saying I'm a complete novice to programming. I've been following a video by Shaun Spalding on kick back. I thought it would be a cool idea to make a game around this mechanic, but I've came a across a problem. When shooting at an angle and the player is propelled the opposite way, the player doesn't move quite the way I thought it would.

Here's a link to Shaun's video. He demonstrates this around the 6 minutes mark:


An example of this mechanic that I'm trying to achieve is Ashe's Coach gun ability from Overwatch but in a 2D environment.

Here's a link to her abilities if you've never played it: https://playoverwatch.com/en-us/heroes/ashe/

Would really appreciate any help given.
 

Nidoking

Member
There's no help to give without information. What is happening that you don't want to happen? What is the code you're using to make that happen?
 
J

JuiceBox

Guest
Hi Nidoking,

Thanks for the reply.

Here's a small video of the issue.

https://drive.google.com/open?id=19Dd268M2oVbk62TSBgIG8-A4O7AGnk_M

When the player shoots diagonally the propelled character seems to move horizontally then immediately up. I was hoping it would arc through the air, opposite to the direction of where the player shot.

This is the code im currenly using;

with (O_Dragonbody)
{
flamekickx = lengthdir_x(60, other.image_angle-180);
flamekicky = lengthdir_y(20, other.image_angle-180);
}

Hopefully, I explained this a little better.
 

Nidoking

Member
That's something, but you've only shown that you set two variables. You haven't shown how you're using the values of those variables to move the character. I suspect that you're using some kind of vertical velocity, but not using horizontal velocity - a platforming tutorial that I once used did that, with the direct action of the left and right movement keys simply causing the character to jump so many pixels according to the variable used for controlling speed. If you want more information than that, you're going to have to provide more information.
 
J

JuiceBox

Guest
That's something, but you've only shown that you set two variables. You haven't shown how you're using the values of those variables to move the character. I suspect that you're using some kind of vertical velocity, but not using horizontal velocity - a platforming tutorial that I once used did that, with the direct action of the left and right movement keys simply causing the character to jump so many pixels according to the variable used for controlling speed. If you want more information than that, you're going to have to provide more information.
Hi Nidoking,

Sorry for the late reply when I followed the video I also added some additional code on the body object, this was:

hsp = (move * walksp) + flamekickx;
flamekickx = 0;

vsp = (vsp + grv) + flamekicky;
flamekicky = 0;

other than that, that's all the code that was used to make the kickback.
 

Nidoking

Member
Okay, and those are two more variables that aren't native Game Maker variables. How are you turning your hsp and vsp values into movement of the character?
 
J

JuiceBox

Guest
Okay, and those are two more variables that aren't native Game Maker variables. How are you turning your hsp and vsp values into movement of the character?
so in the character create Event I have:

hsp = 0;
vsp = 0;
grv = 0.5;
walksp = 4;

flamekickx = 0;
flamekicky = 0;

and in the step event:

//calculate movement

var move = key_right - key_left;

hsp = (move * walksp) + flamekickx;
flamekickx = 0;

vsp = (vsp + grv) + flamekicky;
flamekicky = 0;

if (place_meeting(x,y+1,O_Ground)) && (key_jump)
{
vsp= -10;
}

//H collision
if (place_meeting(x+hsp, y,O_Ground))
{
while (!place_meeting(x+sign(hsp),y,O_Ground))
{
x = x + sign(hsp);
}

hsp = 0;
}

//V collision
if (place_meeting(x,y+vsp,O_Ground))
{
while (!place_meeting(x,y+sign(vsp),O_Ground))
{
y = y + sign(vsp);
}

vsp = 0;
}

x = x + hsp;
y = y + vsp;
 
R

robproctor83

Guest
Your problem is that you are setting the flamekick variables once and then wiping it. In that one step it's moving things by 60/20 pixels which makes it look like it's instantly teleportation and then setting those variables to 0. What you really want to do is make the flamekick variables with a much lower lengthdir value and then animate that value down. So maybe instead try

with (O_Dragonbody)
{
flamekickx = lengthdir_x(3, other.image_angle-180);
flamekicky = lengthdir_y(1, other.image_angle-180);
}

and then here try this instead

hsp = (move * walksp) + flamekickx;
flamekickx *= .8;

vsp = (vsp + grv) + flamekicky;
flamekicky*= .8;

Something like that maybe, it should move the character back over time instead.
 
J

JuiceBox

Guest
Your problem is that you are setting the flamekick variables once and then wiping it. In that one step it's moving things by 60/20 pixels which makes it look like it's instantly teleportation and then setting those variables to 0. What you really want to do is make the flamekick variables with a much lower lengthdir value and then animate that value down. So maybe instead try

with (O_Dragonbody)
{
flamekickx = lengthdir_x(3, other.image_angle-180);
flamekicky = lengthdir_y(1, other.image_angle-180);
}

and then here try this instead

hsp = (move * walksp) + flamekickx;
flamekickx *= .8;

vsp = (vsp + grv) + flamekicky;
flamekicky*= .8;

Something like that maybe, it should move the character back over time instead.

This made a much smoother difference and is defiantly on the right track to what I was after, thank you so much for your help.
 
Top