Object slide on ice in x and y

Discussion in 'Programming' started by Nikolai4, Mar 16, 2019.

  1. Nikolai4

    Nikolai4 Member

    Joined:
    Mar 16, 2019
    Posts:
    2
    Hello! Newbie here. Top down game, object can move in X and Y, 360°
    "Step" is motion_set(image_angle+90, 1);
    and
    "key down" is image_angle+=3;

    So it always move forward and turn left when key press.

    I need to make object slide like on ice little forward of it previous direction while key down, but continue to rotate. Any ideas? I am confused, dont know where to look.
     
  2. Zaxtor99

    Zaxtor99 Member

    Joined:
    Jul 15, 2017
    Posts:
    10
    Set a variable for your object to set your ice slipping motion..
    something like:

    ice_movement = speed / 3; < this needs to be in your step event and make sure you slowly reduce your speed in your step event as long as you aren't holding W or whatever key you use to thrust or give your object "gas"

    Add your ice_movement variable to whatever direction you face.

    For your turning on ice, you'll again need a variable that you can slowly reduce over time..
    You'll have to play with the numbers but maybe something like this:

    ice_turn = 3 <--- set this at the same time you press your key to turn
    turned = true <--- also set this variable when you press your key to turn so you can use it in your step sliding code (seen below)

    once you've started a turn, slowly add the ice_turn to your image_angle but slowly reduce it even if no key is pressed

    so in your step event, you use something like this:

    if turned = true
    {
    image_angle + ice_turn
    ice_turn -= .1;
    if ice_turn <= 0
    {
    ice_turn = 0;
    turned = false;
    }
    }

    That's the basic idea, I hope it helps. You'll likely have to play with the values as I just made stuff up to give you a basic idea of one way to make a sliding feel.
     
    Nikolai4 likes this.
  3. Nikolai4

    Nikolai4 Member

    Joined:
    Mar 16, 2019
    Posts:
    2
    Thanks for help, but still no luck. What I did at the moment
    ice_movement = speed / 3; does not make anything, so I changed it for -0.01;

    Step event

    Code:
    direction=image_angle+90;
    ice_movement = -0.01;
    
    if turned=true{
    speed += ice_movement;
    image_angle+=ice_turn;
    }
    else{
        speed=1;
    }
    if speed <=0{
    speed=0;
    }
    if ice_movement <= 0
    {
    ice_movement = 0;
    turned = false;
    }
    Key down event

    Code:
    turned=true;
    ice_turn=3;

    I little changed your code, because I don't need to stop rotate object while key is pressed. But just because image_angle makes new direction every moment, my object turning to stop by spiral. I need to get an old direction to move object straight while it rotate around its axis.

    How can I add speed variable to direction? Or what did you mean?
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice