Home | Customize | Blog | Extras | Log In | Info
Manual | D&D icons | GML Parser | Archive | Iso City
Username: Password:  
About | Features | Directory | Banners | Contact

Designing Games with GameMaker
Designing Games with GameMaker

Collision checking

When planning motions or deciding on certain actions, it is often important to see whether there are collisions with other objects at certain places. The following routines can be used for this. All these have three arguments in common: The argument obj can be an object, the keyword all, or the id of an instance. The argument prec indicates whether the check should be precise or only based on the bounding box of the instance. Precise checking is only done when the sprite for the instance has the precise collision checking set. The argument notme can be set to true to indicate that the calling instance should not be checked. All these functions return either the id of one of the instances that collide, or they return a negative value when there is no collision.

collision_point(x,y,obj,prec,notme) This function tests whether at point (x,y) there is a collision with entities of object obj.
collision_rectangle(x1,y1,x2,y2,obj,prec,notme) This function tests whether there is a collision between the (filled) rectangle with the indicated opposite corners and entities of object obj. For example, you can use this to test whether an area is free of obstacles.
collision_circle(xc,yc,radius,obj,prec,notme) This function tests whether there is a collision between the (filled) circle centered at position (xc,yc) with the given radius and entities of object obj. For example, you can use this to test whether there is an object close to a particular location.
collision_ellipse(x1,y1,x2,y2,obj,prec,notme) This function tests whether there is a collision between the (filled) ellipse with the indicated opposite corners and entities of object obj.
collision_line(x1,y1,x2,y2,obj,prec,notme) This function tests whether there is a collision between the line segment from (x1,y1) to (x2,y2) and entities of object obj. This is a powerful function. You can e.g. use it to test whether an instance can see another instance by checking whether the line segment between them intersects a wall.

Search Search


Alternative versions Alternative versions

You can also read this manual on one single long page (± 1.5 mb)

Also available in: Dutch French German

ZIP Download helpfile

Advertisement Advertisement

GameMaker Manual