Jump to content


Photo

Character Knockback


  • Please log in to reply
16 replies to this topic

#1 Bewbcake

Bewbcake

    GMC Member

  • New Member
  • 26 posts
  • Version:GM8

Posted 29 May 2012 - 07:21 PM

Hello everyone,
I am working on a 2player scrolling fighting game and I am wondering how we could implement some kind of a knockback? Somebody has given us some knockback code but it only works if (a) the other player doesn't move (B) the other player is in the air. We want there to be a knockback no matter what. We are going for a sort of "interrupt" effect when you get knocked back similar to the one in Super Smash Melee where attacks don't allow you to attack for a while and you can also be juggled. Anyone have any ideas?
My GM version is: 8.1.141 Standard
My characters are chosen in a character selection screen and my character's are obj_P1 and obj_P2 whose sprites and skillsets are changed upon player selection.
Any help would be greatly appreciated thank you!
:D

EDIT: Forgot to mention it is mostly projectile based.

Edited by Bewbcake, 29 May 2012 - 07:21 PM.

  • 0

#2 Sirosky

Sirosky

    GMC Member

  • GMC Member
  • 1323 posts
  • Version:GM8

Posted 29 May 2012 - 07:26 PM

Say you have a bullet object, obj_bullet, and it collides with obj_monster. Place this code in obj_bullet, when it collides with obj_monster.


with(other) //Directs following code at the monster
{speed=other.speed //Gives the monster bullet's speed
direction=other.direction //Optional, depending on your game
}

Edited by Sirosky, 29 May 2012 - 07:26 PM.

  • 1

#3 The Diamond Bullet

The Diamond Bullet

    GMC Member

  • GMC Member
  • 11 posts
  • Version:GM8

Posted 29 May 2012 - 07:35 PM

Well that helped me. Thanks!
  • 0

#4 Sirosky

Sirosky

    GMC Member

  • GMC Member
  • 1323 posts
  • Version:GM8

Posted 29 May 2012 - 07:36 PM

Ehh, it's rudimentary. I'm sure you could find something better than this easily.
  • 1

#5 Bewbcake

Bewbcake

    GMC Member

  • New Member
  • 26 posts
  • Version:GM8

Posted 29 May 2012 - 07:36 PM

Say you have a bullet object, obj_bullet, and it collides with obj_monster. Place this code in obj_bullet, when it collides with obj_monster.


with(other) //Directs following code at the monster
{speed=other.speed //Gives the monster bullet's speed
direction=other.direction //Optional, depending on your game
}


This works but (a) the knockback is too strong and doesn't stop I've tried dividing the other.speed / 5 and that slowed it down but it still keeps going (B) if it pushes them against a wall they get stuck.
  • 0

#6 Sirosky

Sirosky

    GMC Member

  • GMC Member
  • 1323 posts
  • Version:GM8

Posted 29 May 2012 - 07:39 PM

Give obj_monster some friction.

For example, in the create event of obj_monster...

friction=.5 //Change this number until it suits you


Place this in obj_monster for collision event with the wall.

speed=0
//alternatively
move_bounce() //This should work as well.

  • 1

#7 Bewbcake

Bewbcake

    GMC Member

  • New Member
  • 26 posts
  • Version:GM8

Posted 29 May 2012 - 07:55 PM

Give obj_monster some friction.

For example, in the create event of obj_monster...

friction=.5 //Change this number until it suits you


Place this in obj_monster for collision event with the wall.

speed=0
//alternatively
move_bounce() //This should work as well.



For move_bounce() what are the arguments needed? I get an error saying invalid arguments to move_bounce()
  • 0

#8 Tobias(NL)

Tobias(NL)

    GMC Member

  • GMC Member
  • 851 posts
  • Version:Unknown

Posted 29 May 2012 - 08:04 PM


Give obj_monster some friction.

For example, in the create event of obj_monster...

friction=.5 //Change this number until it suits you


Place this in obj_monster for collision event with the wall.

speed=0
//alternatively
move_bounce() //This should work as well.



For move_bounce() what are the arguments needed? I get an error saying invalid arguments to move_bounce()


Use move_bounce_all(true), or if you're using solid walls use move_bounce_solid(true)

Edited by Tobias(NL), 29 May 2012 - 08:05 PM.

  • 1

#9 Bewbcake

Bewbcake

    GMC Member

  • New Member
  • 26 posts
  • Version:GM8

Posted 29 May 2012 - 08:31 PM



Give obj_monster some friction.

For example, in the create event of obj_monster...

friction=.5 //Change this number until it suits you


Place this in obj_monster for collision event with the wall.

speed=0
//alternatively
move_bounce() //This should work as well.



For move_bounce() what are the arguments needed? I get an error saying invalid arguments to move_bounce()


Use move_bounce_all(true), or if you're using solid walls use move_bounce_solid(true)


Thanks Guys!!
If you guys have the time I'm still figuring out how to make my room wrap around since its a scrolling game. But what makes it tricky is its a scrolling game where the direction can change so it needs to wrap around regardless of what direction its scrolling.
  • 0

#10 Sirosky

Sirosky

    GMC Member

  • GMC Member
  • 1323 posts
  • Version:GM8

Posted 29 May 2012 - 08:53 PM

This should solve the issue:

http://wiki.yoyogame...x.php/Move_wrap
  • 0

#11 Bewbcake

Bewbcake

    GMC Member

  • New Member
  • 26 posts
  • Version:GM8

Posted 29 May 2012 - 11:13 PM

This should solve the issue:

http://wiki.yoyogame...x.php/Move_wrap

I'm not sure how this would apply to my game if im using this code for the screen which uses view_xview:


view_xview += scroll_speed; // set horizontal viewspeed to scroll_speed which is is 2
with(obj_P1){
if view_xview > bbox_left{ // checks if objects hitbox is less than the view screen
if place_free(x + view_xview - bbox_left,y){
x += (1 + view_xview - bbox_left); // pushes object with screen so they don't disappear to the left
}
}
}

with(obj_P2){

if view_xview > bbox_left{ // same for player 2
if place_free(x + view_xview - bbox_left,y){
x += (1 + view_xview-bbox_left);
}
}
}

with(obj_P1)
{

if view_xview + view_wview < bbox_right // checks if objects hitbox is greater than the view screen
if place_free(x + view_xview + view_wview - bbox_right,y)
x += 1 + (view_xview + view_wview - bbox_right); // pushes object with screen so they don't disappear to the right
}

with(obj_P2)
{

if view_xview + view_wview < bbox_right // same as player 2
if place_free(x + view_xview + view_wview - bbox_right,y)
x += 1 + (view_xview + view_wview - bbox_right);
}
  • 0

#12 Sirosky

Sirosky

    GMC Member

  • GMC Member
  • 1323 posts
  • Version:GM8

Posted 30 May 2012 - 12:10 AM

In your case, if I'm thinking what you're thinking, you don't need all that code with move_wrap. Put all that code above me in comments, to archive it. And in the step event, put this in as well.

move_wrap(true,true,sprite_width/2) //Wraps the room!

  • 0

#13 Bewbcake

Bewbcake

    GMC Member

  • New Member
  • 26 posts
  • Version:GM8

Posted 30 May 2012 - 04:49 AM

In your case, if I'm thinking what you're thinking, you don't need all that code with move_wrap. Put all that code above me in comments, to archive it. And in the step event, put this in as well.

move_wrap(true,true,sprite_width/2) //Wraps the room!

Didnt work commentated and not commentated :(
  • 0

#14 Tobias(NL)

Tobias(NL)

    GMC Member

  • GMC Member
  • 851 posts
  • Version:Unknown

Posted 30 May 2012 - 07:29 AM

Try placing that last piece of code in the 'outside room' event. Maybe that works?
You can find 'outside room' at the 'other' tab at the events button.

Edited by Tobias(NL), 30 May 2012 - 07:30 AM.

  • 0

#15 Bewbcake

Bewbcake

    GMC Member

  • New Member
  • 26 posts
  • Version:GM8

Posted 30 May 2012 - 08:27 AM

Try placing that last piece of code in the 'outside room' event. Maybe that works?
You can find 'outside room' at the 'other' tab at the events button.

Which object's 'outside room' event are you referring to?
  • 0

#16 Tobias(NL)

Tobias(NL)

    GMC Member

  • GMC Member
  • 851 posts
  • Version:Unknown

Posted 30 May 2012 - 09:09 AM

The object that needs to warp, I think the players?
EDIT: Or do you want to scroll the background accordingly to the player's direction?

Edited by Tobias(NL), 30 May 2012 - 09:13 AM.

  • 0

#17 Bewbcake

Bewbcake

    GMC Member

  • New Member
  • 26 posts
  • Version:GM8

Posted 30 May 2012 - 10:25 AM

The object that needs to warp, I think the players?
EDIT: Or do you want to scroll the background accordingly to the player's direction?

view_xview += scroll_speed; // set horizontal viewspeed to scroll_speed which is is 2
with(obj_P1){
if view_xview > bbox_left{ // checks if objects hitbox is less than the view screen
if place_free(x + view_xview - bbox_left,y){
x += (1 + view_xview - bbox_left); // pushes object with screen so they don't disappear to the left
}
}
}

with(obj_P2){

if view_xview > bbox_left{ // same for player 2
if place_free(x + view_xview - bbox_left,y){
x += (1 + view_xview-bbox_left);
}
}
}

with(obj_P1)
{

if view_xview + view_wview < bbox_right // checks if objects hitbox is greater than the view screen
if place_free(x + view_xview + view_wview - bbox_right,y)
x += 1 + (view_xview + view_wview - bbox_right); // pushes object with screen so they don't disappear to the right
}

with(obj_P2)
{

if view_xview + view_wview < bbox_right // same as player 2
if place_free(x + view_xview + view_wview - bbox_right,y)
x += 1 + (view_xview + view_wview - bbox_right);
}

This code is responsible for the screen scrolling it is in an invisible "controller" object in the room which also holds the values for health, respawn etc...
This code is in its step event.
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users