I wanna do a megaman like knockback in my top down game

P

Purple_Shy_Guy

Guest
This is my first project, so I'm having a bad time trying to figure out how to do it. My knockback wasn't working somedays ago, and the community helped me, so it's working now. But I want to make a knockback just like the one in megaman, because I think it's really dynamic. This is the code I'm using now in the player's state (this is the code that it's working, and not my attempt do to the megaman knockback.):

Code:
if place_meeting(x, y, Obj_Slug) && (cooldown<1) {
    health = health - 1;
    blink = true;
    cooldown = 60;
}

cooldown = cooldown - 1;

if cooldown > 1 {
    blink = true;
} else {
    blink = false
}

nearest_slug = instance_nearest(x, y, Obj_Slug);
if (place_meeting(x, y, nearest_slug)){
    knockback_direction = point_direction(nearest_slug.x, nearest_slug.y, x, y);
    x += lengthdir_x(move_speed*15, knockback_direction);
    y += lengthdir_y(move_speed*15, knockback_direction);
}
Does someone know how to turn it into the megaman knockback or at least have an idea?
 

TheouAegis

Member
You get hit, change sprite to OW! sprite, flash every other frame, move backward until a timer expires, regain control after the timer, keep flashing unable to take damage until a second timer finishes counting down.
 

Nidoking

Member
It's like a regular knockback, but in a cooler game :banana:
Then it sounds like you have to make a cooler game. Apparently with a dancing banana. This is not me being flippant, but you specifying your requirements poorly. I really don't know why so many people on this forum seem to revel in not providing enough information to answer their questions and then laughing at people who can't answer them. You're still the one trying to do something you can't figure out how to do. How do you expect to tell a computer how to do something if you can't even describe to a human what it is you want to do?
 

Mk.2

Member
Then it sounds like you have to make a cooler game. Apparently with a dancing banana. This is not me being flippant, but you specifying your requirements poorly. I really don't know why so many people on this forum seem to revel in not providing enough information to answer their questions and then laughing at people who can't answer them. You're still the one trying to do something you can't figure out how to do. How do you expect to tell a computer how to do something if you can't even describe to a human what it is you want to do?
Slow Fingers didn't start this topic. But the point still stands, OP should describe the knockback behaviour that they want to recreate. Even people who are familiar with Mega Man might not remember every detail of the knockback in the game.
 

Nidoking

Member
Aw, dang. Good spot. So, slightly less condescendingly, describing the functionality has a point beyond helping other people provide help. By describing what you want to do, you make it clearer to yourself what you want to do, which brings you one or more steps closer to being able to program it.
 
P

Purple_Shy_Guy

Guest
You get hit, change sprite to OW! sprite, flash every other frame, move backward until a timer expires, regain control after the timer, keep flashing unable to take damage until a second timer finishes counting down.
My bad, I'm sorry, I should've explained better, but this explanation is pretty much perfect. I've already made a flash shader that works and the invincibility time.
So I just need help to make the character move backward while the sprite is changed to a "hurt sprite" (And I can't control him during this time), and then regain control of the character after this.
But megaman is a 2d platformer game, so the knockback only works to the right and to the left. Since I'm doing a top down game, I also need help to make it work in all the possible directions.
I'm sorry for the I'm sorry for the inconvenience, it was really my bad to assume that everyone knows how megaman's knockback works.
 
Then it sounds like you have to make a cooler game. Apparently with a dancing banana. This is not me being flippant, but you specifying your requirements poorly. I really don't know why so many people on this forum seem to revel in not providing enough information to answer their questions and then laughing at people who can't answer them. You're still the one trying to do something you can't figure out how to do. How do you expect to tell a computer how to do something if you can't even describe to a human what it is you want to do?
Are you serious, Sherlok? I'm seriously expecting an apology for your lack of ability to read and this dislike.
 

ZeGGamer

Member
My bad, I'm sorry, I should've explained better, but this explanation is pretty much perfect. I've already made a flash shader that works and the invincibility time.
So I just need help to make the character move backward while the sprite is changed to a "hurt sprite" (And I can't control him during this time), and then regain control of the character after this.
But megaman is a 2d platformer game, so the knockback only works to the right and to the left. Since I'm doing a top down game, I also need help to make it work in all the possible directions.
I'm sorry for the I'm sorry for the inconvenience, it was really my bad to assume that everyone knows how megaman's knockback works.
Generally, I like to make my code in the Enemy objects and have a script (Or I guess function now in GMS 2.3) that runs when there is a collision that occurs.

This helps as you can tell which side the enemy is on using simple (place empty) or (place meeting) If statements.

repeat this for vertical directions as well.

If(!place_empty(x, y+1, obj_player)) // if the enemy hit the player from above
{
hurt_script // use the code that sends the player Downwards from recoil
}
 
Top