Stuck on Y Values

azimpactazimpact Member Posts: 112
edited November -1 in Working with GS (Mac)
Stuck!
I’m trying to get an actor to be able to jump on another actor to destroy it, but if the other actor hits the first actor from the side, then it’s destroyed instead.

I was able to get the Good Guy actor to jump on the bad guy actor and destroy thanks to Tshirtbooth, but I can’t seem to wrap my head around the math for making the bad guy destroy the good guy when hit from the side.
The good actor is 64 high and the bad guy is 50 high.
To destroy the bad guy, I’ve got the following attribute set:

Game.Player.Y > game.badguys.y +(self.size.height) /1.5621)

My thinking is the Y of Good guy is 32 ( as I understand it, the Y is the center of the actor, perhaps that is where I’m messing up) so if the badguys Y is 25 + (50/1.5621) = 32, then anything above the Y of Good guy will destroy bad guy. This is working

However from the side, when I reverse the formula to apply to the good guy and use the < instead of > the bad buy just passes through the good guy and I can't seem to get the formula to work for that.

Am I correct in understanding that the Y of the actor is the center of the actor?

Any help would be greatly appreciated!

Comments

  • jonmulcahyjonmulcahy Member, Sous Chef Posts: 10,408
    The y value is the players y position on the screen. Y being the distance from the bottom. That y value is calculated from the center point of the actor, so if your actor is a 100x100 square and is 300 pixels off the ground, the y value would be 350.

    I would try something like

    If player.y < badyguy + (1/2 * player.size.height)
  • azimpactazimpact Member Posts: 112
    Would the Y being calculated from the bottom of the screen apply if I constrain the X and Y values to the actor?
  • jonmulcahyjonmulcahy Member, Sous Chef Posts: 10,408
    Y should always be calculated from the bottom, as x is always calculated from the left I can't think of any situation where it wouldn't be.
  • azimpactazimpact Member Posts: 112
    Now that I better understand Y, I'll play around with it and see how I make out.

    Thanks!
  • Metronome49Metronome49 Member Posts: 297
    Aaaah! Y is calculated from the bottom. That makes sense why this thing I was messing with wasn't working as expected.

    In CSS, x & y are calculated from the top left. Had me confused.
  • azimpactazimpact Member Posts: 112
    Success,

    Using jonmulcahy's example, I ended up with:

    game.PlayersY < game.badguysy +(1/2*self.size.height -1)

    Works like a champ!!!
Sign In or Register to comment.