GameMaker [SOLVED][2D Platformer] Jumping out of water when close to wall_obj

Hello
I have the same water physics as in the old counter strike / half life where if you hold space bar, you float towards the water surface. I am trying to make him jump out of the water if close to the "shore"
This code ain't cuttin it
if position_meeting(x,y-20,oWaterWall) and position_meeting(x+3,y,oWall) {
vspeed = 15
}
Notice: oWall = Wall object
oWaterWall = pool of water object
 
W

Walky

Guest
You're using position_meeting (which checks a single point, not two instances). Maybe you meant to use place_meeting()?
Also, keep in mind that even after changing that, the current code will change your vspeed even if you're deep into the water.
 
You're using position_meeting (which checks a single point, not two instances). Maybe you meant to use place_meeting()?
Also, keep in mind that even after changing that, the current code will change your vspeed even if you're deep into the water.
Thanks m8 it seems to work.
if place_meeting(x,y,oWaterWall) and place_meeting(x+3,y,oWall) {
vspeed = -5
}

Now it's just figuring out how to only make him jump near a water surface. Right now he is dragged across walls to his right while being underwater
 
W

Walky

Guest
You can check if the player character will be out of the water if offset by a certain distance:
Code:
if (place_meeting(x, y, oWaterWall) && !place_meeting(x, y-some_distance, oWaterWall) && place_meeting(x+3, y, oWall){
   vspeed = -5;
}
 
You can check if the player character will be out of the water if offset by a certain distance:
Code:
if (place_meeting(x, y, oWaterWall) && !place_meeting(x, y-some_distance, oWaterWall) && place_meeting(x+3, y, oWall){
   vspeed = -5;
}
Basically ! mean not and && mean and
Correct? Also how many &&/and can you have in one if statement? As many as you can remember I think
 
W

Walky

Guest
Yes. You can also use || instead of OR, but that's up to personal preference.

There's no limit to how many logical operators you can use. However, if you find yourself needing to have too many in the same IF then there's probably a better way to approach the problem.
 
Top