Way to tell which side?
DanielA
Member Posts: 101
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
Thanks
Comments
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:
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.
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
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
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).