Triangles

S

Steve Potts

Guest
Hi folks, still very new to GameMaker, but could do with two pieces of help. With the sprite as a large triangle how do I get the collision mask just on the said triangle ? Also I can move the triangle and get it rotating but I want 2 sides to do something which I can do, but if a object hits the third side I want it to do something else is there a way to do this, or a way to use another object "fastened " to one side of said triangle and keep with it when moving and rotating ? Cheers.
 
To get precise collisions, set the collision mask type in the sprite window to Precise.
If its a triangle, you can instead use the function point_in_triangle:
Checks to see whether a given point falls within the defined triangular area.
Since you are rotating the triangle you gotta take that into account as well.

You can check the direction between the triangle and the colliding object to figure out which side he collided with, and do whatever you want with that information.
Also if you store that direction, you can use it to "snap" it to the side which it collided with.
 

TheouAegis

Member
Or you could do vector collisions, but I'm not sure how much faster it would be. Store the coordinates of all 3 points of the triangle in its its create event. Then calculate the collision based on the lines between each point.
 
Top