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?  (Read 2355 times)

0 Members and 1 Guest are viewing this topic.
Knockback?
« on: August 18, 2012, 04:28:54 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 448
I'm trying to add knock back to my engine so that when Link gets hit by an enemy or projectile, he gets pushed back 2 or 3 pixels. I have a terrible excuse for one implemented right now, but it's not accurate at all :/
Right now I only have 1 enemy in my engine, an octorock, and want Link to be pushed back when the rock hits him. I have this code in the rock object to detect what direction it should move:
Code: [Select]
link_pos = point_direction(objOctorok.x,objOctorok.y,objLink.x+1,objLink.y+20)This works great. I was using kind of the same method to figure out which direction Link should be knocked back, but it doesnt take into consideration negative x and y values :/ Help anyone?


Logged

Antidote

>.>
Re: Knockback?
« Reply #1 on: August 18, 2012, 04:55:08 pm »
  • In all seriousness who's serious?
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 1485
What you need is a normalized vector, I'm not sure how this would be done effectively in GM but I know it's possible.
http://www.fundza.com/vectors/normalize/index.html
Logged
  • Axiomatic Data Laboratories
Re: Knockback?
« Reply #2 on: August 18, 2012, 07:42:08 pm »
  • Fear my Blades
  • *
  • Reputation: +3/-0
  • Offline Offline
  • Gender: Male
  • Posts: 562
You've got his direction all that's left is to move him.  Typically you would calculate the x and y components of your vector with cosine and negative sine respectively, but Game Maker provides simple functions for doing it as well.

lengthdir_x(len,dir)
lengthdir_y(len,dir)


On another note, why are you adding 1 and 20 to the player's x and y values?  If it's to adjust for his center things will be WAAY easier for you if you move the offsets on his sprites to his center point instead.  That way his x and y values will already be at his center.
Logged

I've done it (sorta)!  Bloom Lighting in GameMaker, and 3D mode too!  Check out the awesome Screen Saver.
  • Kousou Games
Pages: [1]   Go Up

 


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



Page created in 0.194 seconds with 44 queries.

anything