• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!
  • Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

Question - Code Full Collision Box Affected?

J

JohnJ

Guest
Hello, I am relatively new to GameMaker 2, I am trying to make it so that, when the WHOLE collision box of the Player sprite is on the Water object, then the Player sprite to change to another one that I have made. Currently, the sprite changes when even just 1 pixel of the collission box is on the water, what code should I input, and where, to make it so that the game checks to make sure that the player sprite's collision box is fully in the water before changing the sprite?
 

FrostyCat

Redemption Seeker
One approximation is to check the four corners with position_meeting().
Code:
if (position_meeting(bbox_left, bbox_top, obj_water) && position_meeting(bbox_right, bbox_top, obj_water) && position_meeting(bbox_left, bbox_bottom, obj_water) && position_meeting(bbox_right, bbox_bottom, obj_water)) {
  //...
}
In side-view platformer setups, you can usually get away with just the first left-top condition.
 
J

JohnJ

Guest
One approximation is to check the four corners with position_meeting().
Code:
if (position_meeting(bbox_left, bbox_top, obj_water) && position_meeting(bbox_right, bbox_top, obj_water) && position_meeting(bbox_left, bbox_bottom, obj_water) && position_meeting(bbox_right, bbox_bottom, obj_water)) {
  //...
}
In side-view platformer setups, you can usually get away with just the first left-top condition.
Thanks, so would I put this in the water objects code or the players code?
 

FrostyCat

Redemption Seeker
Thanks, so would I put this in the water objects code or the players code?
Surely you could have figured that out yourself by actually reading the code. I'm tired of this abject lack of initiative shown by recent rookies.

Does "If my top-left, top-right, bottom-left and bottom-right corners collide with water" sound like something your player would ask, or something your water would ask?
 
J

JohnJ

Guest
Surely you could have figured that out yourself by actually reading the code. I'm tired of this abject lack of initiative shown by recent rookies.

Does "If my top-left, top-right, bottom-left and bottom-right corners collide with water" sound like something your player would ask, or something your water would ask?
Thanks for the prompt reply, I was able to assume where this code was supposed to go after posting my last reply, sorry if I had sounded ignorant.
 
Top