Hello Guest, please login or register.
Did you miss your activation email?
Login with username, password and session length.

Pages: [1]   Go Down

Author Topic: Knockback example  (Read 6933 times)

0 Members and 1 Guest are viewing this topic.
Knockback example
« on: December 22, 2010, 05:44:53 am »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 57
Hey there. I am trying to create a GB style zelda game in Gamemaker, but one problem that I have is trying to create enemies that can be pushed back when hit or be pushed back when hit by an enemy. What I mean is that when you strike an enemy wih your sword, or get hit yourself, you get pushed back. But the problem with this is that my own attempts do not take not of collisions with solid objects.

 Another method I have tried is to check if the position from a certain distance is free and jump to that point, but there is likely something better out there and this method is not perfect. I am aiming for something similar to the GB style games, obviously.
Logged

Xiphirx

wat
Re: Knockback example
« Reply #1 on: December 22, 2010, 06:19:02 am »
  • Xiphirx
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3007
About the enemies being bounced back:

I think you could get the angle from the player and the enemy, and move the enemy back a few pixels on that angle... If that made sense (probably didn't)

If you used vectors for positioning, it would be very easy to do D:

If you need help with collision, you can take a look at the GM Minish Cap Engine source code here http://www.zfgc.com/forum/index.php?board=305.0

(btw, I don't use game maker)
Logged
  • For The Swarm
Re: Knockback example
« Reply #2 on: December 22, 2010, 06:44:42 am »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 57
Thanks. The GM engine may be a little complex, but I will try to dig my way through.

 Maybe someone can come in and try to explain how to code uncontrolled collisions with solid objects (when you are knocked back), because that is what I am trying to figure out.
Logged
Re: Knockback example
« Reply #3 on: December 22, 2010, 06:51:12 am »
  • *
  • Reputation: +8/-0
  • Offline Offline
  • Gender: Male
  • Posts: 6604
I think I had knockback in a previous engine release that I did, I removed some of my old GMK files that I had posted but I am pretty sure at least one of Niek's files has Link interacting with a bounce object. It basically works the following way:

- Link is walking up and runs into a bounce object
- this causes Link to be unable to move up and down, sets his y movement speed to be positive (so he goes down) and sets it so he is "slipping"
- if Link is slipping, his movement speed decelerates each step until he stops
- when he stops it is then set so he is able to move up and down again
Logged
Re: Knockback example
« Reply #4 on: December 22, 2010, 08:17:04 am »
  • *
  • Reputation: +9/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3725
The June2010 release has the bouncing in it. But that is moving against a bouncing object. In this case it is a simple matter of reversing the sign of the x/y movement.

However with knockback in a weapons fight it is possible that the character (Link or the enemy) is standing still and you want the characters to move away from each other in the opposite directions. In these cases it are the weapons that do the collisions. But the knockback calculation is the same. Just calculate the difference between positions of the characters, normalized and multiplied by the speed that gives you the movement vector for both characters. Only the position of the character that is used as the origin will have the movement vector multiplied with -1. Or to skip a multiplication, after the normalization multiply one with the speed and the other with a negative speed.
Logged
Re: Knockback example
« Reply #5 on: December 22, 2010, 08:35:09 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 57
I appreciate the help, but I still have some trouble understanding (I'm still a learner in GML). I still am not entirely sure what you want me to do.

Aside from that, I think I have found an overly simple solution, but it worries me a bit. By simply adding a collision event with the wall object (you don't even have to code anything in it!), I was able to get the player to stop moving when he touches that particular object. Is this right? Its seems to be a practical solution, but I am not entirely sure about how it will affect the progress of the game.
Logged
Re: Knockback example
« Reply #6 on: December 22, 2010, 08:54:59 pm »
  • *
  • Reputation: +9/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3725
It is an option. But if you are still that much a beginner with GameMaker, I suggest you read the tutorials provided at yoyo games first and read the GameMaker help files. Those will explain the basics of Game Maker. When you understand that you can work on something more complex as knockback.

What I told you in my previous post is mostly unrelated to any language. It is the basic math behind knockback.
Logged
Re: Knockback example
« Reply #7 on: December 22, 2010, 09:57:37 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 57
For now, I would keep this method (until I can revamp it later) since it currently works. I have been looking through the manual, but I can never find anything explicitly dealing with that issue (any suggestions on what I should learn about?)

Sorry for the trouble. Hopefully when I begin to read up on GML some more, I would better understand your advice.
Logged
Re: Knockback example
« Reply #8 on: December 22, 2010, 10:04:53 pm »
  • *
  • Reputation: +9/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3725
It is not GML specific, but GameMaker in general. Just start by going through the tutorials at www.yoyogames.com. And off course the help files. It is best to know what events do and in what order they are executed.
Logged
Re: Knockback example
« Reply #9 on: April 25, 2011, 02:26:59 am »
  • The king of Awesome
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 198
I know I'm bumping but this is what I use.
Code: [Select]
x1 = argument0;
y1 = argument1;
x2 = argument2;
y2 = argument3;
degree = radtodeg(arctan2(argument1 - argument3, argument2 - argument0));
direction=point_obj_dir(global.herox,global.heroy,ai_hit_l.x,ai_hit_l.y)
Logged

Xiphirx

wat
Re: Knockback example
« Reply #10 on: April 25, 2011, 02:34:19 am »
  • Xiphirx
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3007
Please do not grave dig topics.

Closed.

Songshui, if you want this to be re-opened, please message the administration.
Logged
  • For The Swarm
Pages: [1]   Go Up

 


Contact Us | Legal | Advertise Here
2013 © ZFGC, All Rights Reserved



Page created in 0.091 seconds with 60 queries.

anything