Way to tell which side?

DanielADanielA Member Posts: 101
edited November -1 in Working with GS (Mac)
Is there a way to tell if a block fell on top of my actor, but if its in front of him he will just hit it? Or if my actor is walking on top of the ground or if he hits the side of the ground?
Thanks

Comments

  • JackBQuickJackBQuick Member Posts: 524
    Could you compare the position of the block to the position of the actor?

    As an example, here is a diagram I used to help me place squares -- each 80 pixels by 80 pixels in size -- onto the screen:

    image

    The numbers in the brackets represent the x- and y-coordinates of each actor. You can find these coordinates in the actor's attributes. So, for example, the top left square is positioned at (40, 280) -- in other words, that's where its center is located: 40 pixels to the right from the bottom left of the screen, and 280 pixels up.

    As you can see, if you compare two actors' coordinates:

    a) the higher actor has a greater y-coordinate (the second number) than one beneath it, and
    b) an actor to the right of another has a greater x-coordinate (the first number).

    So, if you compare the actors' positions when they collide, you can determine their positions relative to each other.
  • JackBQuickJackBQuick Member Posts: 524
    And, if you have the coordinates of both the actors, you can also use vectorToAngle. You can find more information about it on this page:

    Expression Editor (pop-up) Reference

    firemaplegames explains what you need to do well in this forum topic:

    Need to be good at maths :) Directional Animation

    Actually, forget the mumbo jumbo that I wrote earlier and just read what firemaplegames wrote :)
  • FatalCrestFatalCrest Member Posts: 113
    You can just have 4 attributes:PlayerX, PlayerY, BlockX, BlockY,

    Have an updater rule that grabs their X and Y positions and place them into those global attributes.

    Then make this rule,

    If actor collides or overlaps with actor block and BlockY is greater than PlayerY
    (your code here)

    Have the other X coordinates for your detection on the side.

    Hope it works! ;3
  • JackBQuickJackBQuick Member Posts: 524
    FatalCrest said:
    You can just have 4 attributes:PlayerX, PlayerY, BlockX, BlockY,

    Have an updater rule that grabs their X and Y positions and place them into those global attributes.

    Then make this rule,

    If actor collides or overlaps with actor block and BlockY is greater than PlayerY
    (your code here)

    Have the other X coordinates for your detection on the side.

    Hope it works! ;3

    I think this will only work if both actors are aligned vertically or horizontally (so that the difference between either the x-coordinates or the y-coordinates will be zero).

    If an actor comes in on an angle, you will have problems. For instance, it is possible for both BlockY to be greater than PlayerY, AND BlockX to be greater than PlayerX AT THE SAME TIME.

    I was thinking along these lines until I read firemaplegames's solution. Then, I realized that his answer was better. By determining the angle between actors, you are better able to determine the direction of impact. For example, if the angle is between 45 degrees and 135 degrees, then the top of the actor is hit.

    I realize now that my directive to "just read what firemaplegames wrote" might be taken as glib but I didn't mean it that way. He provided a better and more efficient solution than what I was offering, and I wanted DanielA to follow firemaplegames's advice.

    I should have explained myself better (and I should have searched the forum before I began to write my opinion).
Sign In or Register to comment.