collision_ellipse

collision_ellipse uses the first four arguments (x1,y1,x2,y2) to define the width and height of an ellipse within the current room and then checks to see if any object or tile map that is defined by the "obj" argument is in collision with that area. This collision can be checked as precise or not, and you may also choose to check for the instance running the code itself or not. Consider this image:

Collision ellipse exampleHere, the instance in the middle is using a collision ellipse to check for ball objects. Now, the blue ones do not have a precise bounding box and as you can see, even if the sprite is not actually touching the ellipse, the collision can still happen (even if you set the precise option in the function to true) as the bounding box of that sprite over-laps the elliptical area defined by collision_circle. On the other hand, the green balls will only be considered in collision if the actual sprite over-laps the defined ellipse. Remember, for precise collisions to be considered both the object sprite and the collision function must have precise marked as on.

This function will return the unique id of the instance being collided with, or the Tile Map Element ID of the tile map found. If no collisions are found, noone is returned.

In addition to objects and instances, the function also accepts:

Passing an array allows you to check for collisions against multiple objects and/or Tile Maps in one call.

 

Syntax:

collision_ellipse(x1, y1, x2, y2, obj, prec, notme);

ArgumentTypeDescription
x1RealThe x coordinate of the left side of the ellipse to check.
y1RealThe y coordinate of the top side of the ellipse to check.
x2RealThe x coordinate of the right side of the ellipse to check.
y2RealThe y coordinate of the bottom side of the ellipse to check.
objObject Asset or Object Instance or Tile Map Element ID or ArrayAn object, instance, tile map ID, keywords all/other, or array containing these items
precBooleanWhether the check is based on precise collisions (true, which is slower) or its bounding box in general (false, faster).
notmeBooleanWhether the calling instance, if relevant, should be excluded (true) or not (false).

 

Returns:

Object Instance or Tile Map Element ID or noone

 

Example:

if (collision_ellipse(50, 50, 200, 100, obj_Player, false, true) != noone)
{
    instance_create_layer(obj_Player.x, obj_Player.y, "Effects", obj_Splash);
}

This will check an elliptical zone within the bounds of 50x, 50y and 200x, 100y for the object "obj_Player". If there is a collision with that object, then it will create an instance of "obj_Splash" at the x/y coordinates of obj_Player.