Platform_JumpThrow_Rotation

Discussion in 'Tutorials' started by jonjons, Dec 5, 2018.

  1. jonjons

    jonjons Member

    Joined:
    May 10, 2017
    Posts:
    243
    GM Version: Studio 2
    Target Platform: Windows
    Download: https://drive.google.com/file/d/1PkhncvRO1H8FjWwYfWSNH96eR_vj0w8n/view?usp=sharing

    MarketPlace: https://marketplace.yoyogames.com/assets/7649/platformanglejumpthrow

    Links: N/A
    Description:
    Here's a small solution i wanted to share for jumping throw platforms that have a rotation value / collision.
    Ive searched a lot before doing it, i coulnt find anything related to this problem.

    The solution i found is very simple, before trying all the cos and sins and collisions checks.
    A simple place_metting(A) < place_metting(B) seems to work fine.


    Before moving foward the player must be walking on slopes I'am using the slopes from: Zack Bell Games
    https://zackbellgames.com/2014/10/28/devlog-creating-a-platformer/

    After the Slope movement is working correctly:

    [​IMG]

    make an object:
    - obj_Platform_Rotation
    - object: obj_sensor
    - both sprites objects are 32x32 with collision: rectangle with rotation

    next:

    [​IMG]

    In obj_Platform_Rotation the sensor must be identical to its shape.
    The obj_sensor will be one checking for the player collision.
    platGo is a variable in the player object that tells us when the player wants to move down the platform.

    obj_Platform_Rotation
    create event:
    Code:
    /// @description Insert description here
    
    sensor = instance_create_depth(x, y, depth, obj_sensor);
    sensor.x = x;
    sensor.y = y;
    sensor.image_xscale = image_xscale;
    sensor.image_yscale = image_yscale;
    sensor.image_angle = image_angle;
    
    obj_Platform_Rotation
    step event:
    Code:
    /// @description
    // 22 defines the maximum player height, or the number to check between the two collisions
    
    
    with ( obj_player )
    {
        if ( place_meeting(x, y, obj_sensor) < place_meeting(x, y+22, obj_sensor) && platGo == 0 ) // 22
        {
            depth = -210;
            obj_Platform_Rotation.sprite_index = spr_Platform_Rotation;
        }
        else
        {
            depth = 0;
            obj_Platform_Rotation.sprite_index = -1;
        }
    }
    
    With this if ( place_meeting(x, y, obj_sensor) < place_meeting(x, y+22, obj_sensor) )
    The player will be able to jump throw Angle plaforms, like he does in the code used on static Platforms:

    platform withOut rotation
    obj_Platform
    step event:
    Code:
    if (obj_player.bbox_bottom > bbox_top || obj_player.platGo > 0)
    {
        //mask_index = -1;
        sprite_index = -1;
    }
    else
    {
        //mask_index = spr_Platform;
        sprite_index = spr_Platform;
    }
    
    ///////////////////////////////////////////-------------/////////////////////
    ///////////////////////////////////////////-------------/////////////////////
    ///////////////////////////////////////////-------------/////////////////////

    here's the full project code
    [​IMG]


    the player image size is 89W 69H
    collision mask maual
    36 __ 53
    20 __65
    off set: x45 y65
    [​IMG]

    All other sprite objects in the game are 32x32
    and obj_wall_Parent is set to be the parent of all other collision objects, except for obj_sensor
    (
    obj_wall_Rotation
    obj_Platform
    obj_Platform_Rotation
    )

    Player Code: //---------------------//----------------------//--
    create event
    Code:
    /// @description Insert description here
    
    canMove = 1; //--TOGGLE-MOVE-ON/OFF--
    walksp = 3; //--WALK-SPEED-
    hsp = 0; //--HORIZONTAL-
    vsp = 0; //--VERTICAL-
    grv = 0.2; //--GRAVITY-ACCELARATION-
    jumpSP = -7; //--JUMP-SPEED-
    
    platGo = 0; //--GOING-THROW-PLATFORMS--
    grounded = 0; //-0-pl-stand-/-2-pl-duck-/-1-pl-onAir---
    
    img_spd = 0;
    image_speed = img_spd;
    
    spr_ind = spr_plrIdle;
    sprite_index = spr_ind;
    
    step event
    Code:
    /// @description Insert description here
    
    key_left = keyboard_check(vk_left);
    key_right = keyboard_check(vk_right);
    key_duck = keyboard_check(vk_down);
    key_jump = keyboard_check_pressed(ord("Z"));
    key_fire= keyboard_check(ord("X"));
    
    
    
    
    //---//--GRAVITY--//----------------------------------------
    if (vsp < 14 && grounded == 1)
    {
        vsp += grv;
    }
    
    
    //---//--INPUT-LEFT-RIGHT--//-------------------------------
    if (canMove == 1)
    {
        var move = key_right - key_left;
        hsp = move * walksp;
    }
    
    //---//--PLR-JUMP--//----------------------------------------
    if ( grounded == 0 && key_jump )
    {
            vsp = jumpSP;
    }
    
    
    //-----------//-----PLAYER-MOVE-VERTICAL-----//--------------
    
    repeat(abs(vsp))
    {
        if (!place_meeting(x, y + sign(vsp), obj_wall_Parent))
        {
            y += sign(vsp);
        }
        else
        {
            vsp = 0;
            break;
        }
    }
    
    //-----------//-----PLAYER-MOVE-HORIZONTAL-----//------------
    if (canMove == 1)
    {
        repeat(abs(hsp))
        {
            // Move up slope
            if (place_meeting(x + sign(hsp), y, obj_wall_Parent) && !place_meeting(x + sign(hsp), y - 1, obj_wall_Parent))
            {    --y;    }
            // Move down slope
            if (!place_meeting(x + sign(hsp), y, obj_wall_Parent) && !place_meeting(x + sign(hsp), y + 1, obj_wall_Parent) && place_meeting(x + sign(hsp), y + 2, obj_wall_Parent))
            {    ++y;    }
    
            if (!place_meeting(x + sign(hsp), y, obj_wall_Parent))
            {
                x += sign(hsp);
            }
            else
            {
                hsp = 0;
                break;
            }
        }
    }
    
    //----------------------------------//---------//-------------
    
    //-------//--CALC-PL-VARS-TO-BE-USED-ON-PL-MODE--//--------------
    
    if ( place_meeting ( x, y+1, obj_wall_Parent) && key_duck)
    {
        image_index = 2;
        grounded = 2;  //----//-plr-duck-------------
        canMove = 0;
    }
    else if ( place_meeting ( x, y+1, obj_wall_Parent) && vsp >= 0 ) //--vsp-negative-moves-the-plr-UP
    {
        if ( key_right || key_left )
        {
            image_index = 1;
        }
        else
        {
            image_index = 0;
        }
        grounded = 0;  //----//--plr-stand------------
        canMove = 1;
    }
    else
    {
        image_index = 3;
        grounded = 1;  //----//--plr-onAir----------------
        canMove = 1;
    }
    
    
    //-----//--PLR-FACING-RIGHT-LEFT--//--------------------------------
    if ( key_right || key_left )
    {
        image_xscale = key_right - key_left;
    }
    
    
    //------//--GOING-THORW-PLATFORMS--//--------------------------------
    if ( grounded == 2 && key_jump && platGo == 0)
    {
        platGo = 0.2;
    }
    if (platGo > 0)
    {
        platGo -= delta_time/1000000;
        platGo = clamp(platGo, 0, 1);
    }
    
    //------//--TEST--PLAYER-STUCK-INSIDE-WALL-//--------------------------------
    if (key_fire)
    {
        y -= 3;
        vsp = 0;
    }
    
    
    Remaing objects code

    [​IMG]

    obj_platform //---------------------//----------------------//--
    step event:
    Code:
    /// @description Insert description here
    
    if (obj_player.bbox_bottom > bbox_top || obj_player.platGo > 0)
    {
        //mask_index = -1;
        sprite_index = -1;
    }
    else
    {
        //mask_index = spr_Platform;
        sprite_index = spr_Platform;
    }
    
    obj_Platform_Rotation //---------------------//----------------------//--
    create event
    Code:
    /// @description Insert description here
    
    sensor = instance_create_depth(x, y, depth, obj_sensor);
    sensor.x = x;
    sensor.y = y;
    sensor.image_xscale = image_xscale;
    sensor.image_yscale = image_yscale;
    sensor.image_angle = image_angle;
    
    
    step event
    Code:
    /// @description
    // 22 defines the maximum player height, or the number to check between the two collisions
    
    
    with ( obj_player )
    {
        if ( place_meeting(x, y, obj_sensor) < place_meeting(x, y+22, obj_sensor) && platGo == 0 ) // 22
        {
            depth = -210;
            obj_Platform_Rotation.sprite_index = spr_Platform_Rotation;
        }
        else
        {
            depth = 0;
            obj_Platform_Rotation.sprite_index = -1;
        }
    }
    
    --------------------//---------misc------//----------------
    obj_options---------------------//----------------------
    create event
    Code:
    /// @description Insert description here
    
    display_set_gui_maximize(2, 2, 1, 20);
    
    change = false;
    
    step event
    Code:
    /// @description Insert description here
    
    if ( keyboard_check_pressed(vk_escape) )
    {
        game_end();
    }
    if ( keyboard_check_pressed(vk_enter) )
    {
        room_restart();
    }
    
    if ( keyboard_check_pressed(vk_space) )
    {
        change = ! change;
        window_set_fullscreen(change);
    }
    
    draw_gui event
    Code:
    /// @description Insert description here
    
    draw_set_color(c_black);
    
    draw_text(20, 20, "MOVE: LEFT / RIGHT");
    draw_text(20, 35, "DUCK: DOWN");
    draw_text(20, 50, "JUMP: Z");
    draw_text(20, 65, "PLAT DOWN: DOWN + Z");
    draw_text(20, 80, "TEST IAM STUCK: X");
    
    
    if ( instance_exists( obj_player )  )
    {
        draw_text(20, 110, "PLAYER SPEED_H: " + string( obj_player.hsp ));
        draw_text(20, 125, "PLAYER SPEED_V: " + string( obj_player.vsp ));
        draw_text(20, 140, "PLAYER PLAT_GO: " + string( obj_player.platGo ));
        draw_text(20, 155, "GROUNDED: " + string( obj_player.grounded ));
        draw_text(20, 170, "CAN_MOVE: " + string( obj_player.canMove ));
    }
    
    draw_text(20,200, "FULL SCREEN/WINDOW: SPACE");
    draw_text(20,215, "EXIT GAME: ESCAPE");
    draw_text(20,230, "RESTART GAME: ENTER");
    
    
    draw_set_color(c_white);
    

    Note that if some AngleJumpPlatforms seem to fail sometimes, you need to check the normal walls rotation slopes, and see if the player is not getting stuck inside the wall... Once all slopes are working fine for normal walls, the obj_Platform_Rotation should work 100%.
     
    Last edited by a moderator: Dec 5, 2018
    mamacato and NeZvers like this.
  2. Jack McRip

    Jack McRip Member

    Joined:
    Dec 25, 2018
    Posts:
    8
    Thank you
    :)
     

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