Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

The Peri Sucks at GML Thread

I'm sure I'll have plenty of questions about GML as I attempt to learn it, so I'll be posting them in this thread. Help is appreciated.

I'm trying to figure out how to use the collision functions. Just as a test, I put this in a (perhaps someday) pushable object's collision event with player1:
show_message(string(collision_point(player1.x,player1.y,par_pushable,true,false)))

But it always returns -4. According to the documentation, a negative number means there's no collision. What am I doing wrong? The message box wouldn't pop up if they weren't colliding! Is it only testing the origin of the player1 object or something? Is there a way to check the collision masks instead? There doesn't appear to be a function for that in the collisions documentation, but it would be really useful to be able to do that in code... Do I just have to use the event?

Relevant Documentation":1f4ubj11 said:
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.
 
you can add a value to the x and/or y variables to check a different position, so if you want to check if there is a collision 10 pixels in front of the origin, you would use player1.x+10

otherwise you could check if there is a collision within a shape, which would sort of function like a bounding box. Just use the collision_rectangle, collision_circle, or collision_ellipse commands.
 
I thought about doing that, but it seemed inelegant. I'd rather have precise collisions. I dunno, it just seems like there should be a way to check collision masks in GML. If you can do it in an event, why not in GML? Thanks for the suggestion, though. I'll do that if I can't find a better way.
 
And there is, I think you have to setup the mask in the object dialog when you create it, then it uses the mask to check the collision, also, if I am not mistaken there is a variable that is used to set the mask for the collision , but I don't remember its name, I will try to find the project, and hopefully I can be of better help,(haven't messed in GameMaker for years).

Edit: Just remembered the Name of the variable:

mask_index=sprite; //Set this to the Sprite you which to use as collision mask. and you are done, me thinks.
Code:
 

instance_place(x,y,obj)

place_meeting(x, y, objc)

Those are the functions you need ;), if unsure on what to use, check the documention for each of them, they do the same, but retrive diferent things.
Good Luck
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top