Welcome Guest ( Log In | Register )

[ Big| Medium| Small] -



Post new topic Reply to topic  [ 6 posts ] 
    Perihelion
  Fri Mar 11, 2011 9:54 pm
Peril Hellion
User avatar
Sponsor

Inept Evil Stooge
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:
Quote:
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 wrote:
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.

_________________


Top Top
Profile      
 

    Dr. Funk
  Sat Mar 12, 2011 12:05 am
I AM THE RAP GAME
User avatar
Member

whenever using x and y variables for an object it always checks at the origin of that objects sprite, so I'm guessing there isn't a collision at that specific point.


Top Top
Profile      
 

    Perihelion
  Sat Mar 12, 2011 12:17 am
Peril Hellion
User avatar
Sponsor

Inept Evil Stooge
Yeah, I figured that was the problem. I'm not sure how to do it correctly, though.

_________________


Top Top
Profile      
 

    Dr. Funk
  Sat Mar 12, 2011 12:41 am
I AM THE RAP GAME
User avatar
Member

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.


Top Top
Profile      
 

    Perihelion
  Sat Mar 12, 2011 12:43 am
Peril Hellion
User avatar
Sponsor

Inept Evil Stooge
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.

_________________


Top Top
Profile      
 

    Morphex
  Sat Mar 12, 2011 6:35 am
Member

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.
Expand to see the code.


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

_________________
http://www.morphexe.com/Blog/4009/beta-testing-the-engine-online


Top Top
Profile      
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 


Who is online

Users browsing this forum: No users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

We are an independent, not-for-profit game making community.
Homepage
Board Index
About Us
Downloadable Games
Free Browser Games
Games in Development
RPG Maker Support
Game Maker Support
Construct 2 Support
HBGames the eZine
Advanced RPG Maker
Site Announcements
Powered by phpBB © phpBB Group