I want to reduce vsp player in the water but...

Arlan64

Member
Hello world!

I've a problem with my player when he plunges in the water...

I want to make the player slow down when he dives into the water, while keeping jumping into the water.
The problem is this: when I set the vertical speed lower in the water than on the surface, the player gets stuck in that speed and even if I try to jump into the water, the player does not allow it.

That's why I appeal to you! The best help will be welcome :)

I will give you the codes, so you can find your way around (check in Step Event the long line "---", this is the place of the problem (I think...?)):

Blooby >> Create:
Code:
///Initialisation des variables

//Saisir la gravité initiale
grav_normal = 0.50;
grav_water = 0.45;

grav = grav_normal;
//Saisir la vitesse horizontale initiale
hsp = 0;
//Saisir la vitesse verticale initiale
vsp = 0;
//Saisir le nombre de sauts initial au sol
jumps = 0;

//Saisir le nombre de sauts maximum initiaux
jumpsmax = 1;
jumpsmax_water = 999999;
//Saisir le nombre de sauts dans les airs
jumps_outside = 0;

//Saisir la vitesse du saut initial (la hauteur plutôt)
jumpspeed_normal = 10;
//Saisir la vitesse du saut avec le HighJump PowerUp (la hauteur plutôt)
jumpspeed_powerup = 13.8;
//Saisir la vitesse de nage verticale initiale
jumpspeed_water = 7.2;

//Saisir la vitesse de saut qui est égale à la vitesse de saut normale
jumpspeed = jumpspeed_normal

//Saisir la vitesse de déplacement initiale
movespeed_normal = 6;
//Saisir la vitesse de déplacement avec le HighSpeed PowerUp
movespeed_powerup = 10;
//Saisir la vitesse de nage horizontale initiale
movespeed_water = 4

//Saisir la vitesse de déplacement qui est égale à la vitesse de déplacement normale
movespeed = movespeed_normal

//Saisir la dose de ralentissement/freinage quand le joueur plonge
stop_water = 0;

//Saisir la collision initiale avec les ennemis
touch_ennemies = 0;
Blooby >> Step:
Code:
///Les déplacements de Blooby

//Les commandes
key_right = keyboard_check(vk_right);
key_left = -keyboard_check(vk_left);
key_jump = keyboard_check(vk_up);
key_jump_held = keyboard_check(vk_up);
key_jump_pressed = keyboard_check_pressed(vk_up);
key_down = -keyboard_check_pressed(vk_down);
key_down_held = -keyboard_check(vk_down);

//Réactions aux déplacements basiques
move = key_left + key_right;
hsp = move * movespeed;
{if (vsp < 10)
    {
     vsp += grav;
    }
}

//Pentes

{if (key_right)
   {if place_meeting(x + 6,y,obj_slope_UpRight)
    y = y - 6
   }
}

{with (key_left)
   {if place_meeting(x - 6,y,obj_slope_UpLeft)
    y = y - 6
   }
}

//Prise d'appui au sol pour sauter
{if place_meeting(x,y+1,obj_floor)
    {
     vsp = key_jump * -jumpspeed;
    }
} 
//Dash en l'air
{if place_empty(x,y+1)
    {
     vsp += key_down * -jumpspeed;
    }
}

//Sauts dans l'eau
{if (place_meeting(x,y,obj_water) && key_jump_pressed) || (place_meeting(x,y+1,obj_floor) && place_meeting(x,y,obj_water) && (key_jump || key_jump_held || key_jump_pressed))
    {
     vsp = key_jump_pressed * -jumpspeed_water;
    }
}

//Pas de sauts en dehors de l'eau
{if place_empty(x,y)
    {
     jumps = jumps_outside;
     grav_water = grav_normal;
     stop_water = 0;
    }
}

//Hauteurs de sauts à chaque 4 pixels
{if (vsp < 0) && (!key_jump_held)
    {
     vsp = max(vsp,-jumpspeed/4)
    }
}

//Ralentissements dans l'eau --------------------------------------------------------------------------------
{if place_meeting(x,y,obj_water)
    {
     hsp = move * movespeed_water
     //vsp = grav_water * jumpspeed_water
    }
}

/*{if vsp = grav_water * jumpspeed_water
    {
     vsp = key_jump_pressed * -jumpspeed_water;
    }
}

{if stop_water = 1
      {
       //vsp = grav_normal * grav_water
      }
}*/

///Collisions avec le sol/mur

//Collision horizontale
{if place_meeting(x+hsp,y,obj_floor)
    {
     while !place_meeting(x+sign(hsp),y,obj_floor)
        {
         x += sign(hsp);
        }
     hsp = 0;
    }
}
x += hsp;

//Collision verticale
{if place_meeting(x,y+vsp,obj_floor)
    {
     while(!place_meeting(x,y+sign(vsp),obj_floor))
        {
         y += sign(vsp);
        }
     vsp = 0;
    }
}
y += vsp;
 

Kasra_n

Member
try this method:
1. set a same parent for player and water object

Code:
//Create Event
v_speed = 5;
interupt = false;

if object_meeting(obj_parent, x, y)
{
    if (!interupt)
    {
        interupt = true;
        vspeed -= something;
    }
}
else
{
    if(interupt)
    {
          interupt = false;
          v_speed += something;
    }
}
iam on mobile, i may write the meeting function wrong but this method works
 

Arlan64

Member
try this method:
1. set a same parent for player and water object

Code:
//Create Event
v_speed = 5;
interupt = false;

if object_meeting(obj_parent, x, y)
{
    if (!interupt)
    {
        interupt = true;
        vspeed -= something;
    }
}
else
{
    if(interupt)
    {
          interupt = false;
          v_speed += something;
    }
}
iam on mobile, i may write the meeting function wrong but this method works
I've placeed "interupt = false;" in Create Event of the player, the rest of the code I put in Step Event of the player. I've deleted your variable "v_speed" because it's already there (normaly)

I rectified the place_meeting (your object was in the first placement but I move this in the last placement)

Now, the player does'nt slow down... He's just "floating" a little in the surface of the water
 

Arlan64

Member
I've placeed "interupt = false;" in Create Event of the player, the rest of the code I put in Step Event of the player. I've deleted your variable "v_speed" because it's already there (normaly)

I rectified the place_meeting (your object was in the first placement but I move this in the last placement)

Now, the player does'nt slow down... He's just "floating" a little in the surface of the water
But should everything be in the create event?
 

Arlan64

Member
try this method:
1. set a same parent for player and water object

Code:
//Create Event
v_speed = 5;
interupt = false;

if object_meeting(obj_parent, x, y)
{
    if (!interupt)
    {
        interupt = true;
        vspeed -= something;
    }
}
else
{
    if(interupt)
    {
          interupt = false;
          v_speed += something;
    }
}
iam on mobile, i may write the meeting function wrong but this method works
The player slow down but I want the player to jump into the water and not go up while standing, and furthermore, the player after he has slowed down, he goes back gently to the surface and that's not really what I want. It is necessary that the player can go down in the water (because I conceive levels aquatic in which the player could swim freely and simply). I put you the current code that I studied for hours:

Code:
{if place_meeting(x,y,obj_water)
     interupt = true;
else
    {
     interupt = false;
    }
    {if interupt = true
           {
            vsp -= 1.5;
            if vsp = 0
               {
                interupt = false;
               }
           }
    }
}
And I'm lost a little.. :(
 
Top