Jump to content


Photo

Bounce against enemy


  • Please log in to reply
8 replies to this topic

#1 peco

peco

    GMC Member

  • New Member
  • 28 posts
  • Version:GM8

Posted 30 April 2012 - 10:13 PM

Hello all awesome game makers.
I'm trying to make my player character bounce against the enemies. But I don't just want him to bounce, I want him to bounce the right direction,
i.e. if the enemy is moving South, I want the PC to bounce south, if the enemy is moving West I want the pc to bounce west etc.
I'd try to figure this one out on my own, but time is of the essence in this case...

Any nifty piece of code out there for this?

Something like: "if vspeed>hspeed && character x-position > enemy x-position - then jump character to X 3 relative... else x-3 relative...?
or whatever you think best.

I appreciate all and any help.
  • 0

#2 Ventwig

Ventwig

    GMC Member

  • New Member
  • 279 posts

Posted 30 April 2012 - 10:52 PM

Are you just trying to get him to move in the right direction, as in the direction the enemy's going?
If so, you could just make the player's v/h speed equal to the enemy's.
  • 0

#3 peco

peco

    GMC Member

  • New Member
  • 28 posts
  • Version:GM8

Posted 01 May 2012 - 08:57 AM

Are you just trying to get him to move in the right direction, as in the direction the enemy's going?
If so, you could just make the player's v/h speed equal to the enemy's.


That's exactly what I'd like to do! As long as the enemy doesn't pull along the character when it turns... (moves in a square path).
Only it seems my GM-coding skills aren't up to the task. How is that done exactly?
  • 0

#4 C_Pike

C_Pike

    GMC Member

  • GMC Member
  • 619 posts
  • Version:GM8.1

Posted 01 May 2012 - 10:41 AM

I think it would be something like:

//in the collision event for enemy.
hspeed = other.hspeed;
vspeed = other.vspeed;
x = xprevious;
y = yprevious;

I'm not sure that will work though :whistle:
  • 0

#5 peco

peco

    GMC Member

  • New Member
  • 28 posts
  • Version:GM8

Posted 03 May 2012 - 02:40 PM

Sorry. Can't get your code to work. Might be cause of my nubedome though.
Any other ideas?
I'm surprised there's no tutorial on such a common feature as this one.
  • 0

#6 C_Pike

C_Pike

    GMC Member

  • GMC Member
  • 619 posts
  • Version:GM8.1

Posted 03 May 2012 - 03:30 PM

OH! You want the enemy to PUSH the player, not PULL the player! (we were all thinking pull)

There is a nudge code:
10: Push-off Collision
{
// in collision event with whatever object...
var_dir = point_direction(x,y,other.x,other.y)
x = x+lengthdir_x(-1,var_dir)
y = y+lengthdir_y(-1,var_dir)
}

Basically, what this code does is gently 'pushes' off the object your colliding with, in the shortest possible pathway! So if you get 'stuck' in an object, using this will kick you out of it, or if you have object always going on-top of each other, using this will keep them apart... In short, a VERY handy code. I like to use it with while(place_meeting(x,y,other))
Taken from Smart Codes

Edited by C_Pike, 03 May 2012 - 03:30 PM.

  • 0

#7 peco

peco

    GMC Member

  • New Member
  • 28 posts
  • Version:GM8

Posted 03 May 2012 - 09:25 PM

OH! You want the enemy to PUSH the player, not PULL the player! (we were all thinking pull)


I guess I wasn't very clear on what effect I wanted...
Thank you very much though! This does exactly what I want. This forum is great!
Now I just gotta figure out how not to get pushed into solid objects. It never ends, does it :) .
  • 0

#8 C_Pike

C_Pike

    GMC Member

  • GMC Member
  • 619 posts
  • Version:GM8.1

Posted 03 May 2012 - 09:30 PM


OH! You want the enemy to PUSH the player, not PULL the player! (we were all thinking pull)


I guess I wasn't very clear on what effect I wanted...
Thank you very much though! This does exactly what I want. This forum is great!
Now I just gotta figure out how not to get pushed into solid objects. It never ends, does it :) .


Have a parent object that is called obj_solid (but DON'T check the solid box). Link your walls and enemies to the parent, and set the collision code for the parent as opposed to the enemy. If you get glitches, like popping through walls, just make it so you are destroyed when you get between a wall and an enemy (or if you are inside a wall, is easier)

Edited by C_Pike, 03 May 2012 - 09:31 PM.

  • 0

#9 peco

peco

    GMC Member

  • New Member
  • 28 posts
  • Version:GM8

Posted 04 May 2012 - 02:53 PM

Have a parent object that is called obj_solid (but DON'T check the solid box). Link your walls and enemies to the parent, and set the collision code for the parent as opposed to the enemy. If you get glitches, like popping through walls, just make it so you are destroyed when you get between a wall and an enemy (or if you are inside a wall, is easier)


Sweet. Everything runs smoothly now. I made a few alterations in the levels too.
Thanks for yer help!
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users