Search Unity

Help with porting Game Maker project to Unity

Discussion in '2D' started by Blackgarden, Dec 23, 2015.

  1. Blackgarden

    Blackgarden

    Joined:
    Oct 23, 2015
    Posts:
    11
    So, Im trying to port a part of my game maker project to unity.

    I realize that the create event, step event functions can be replaced by void start, void update in unity, but Im needing for help to "translate" the other details.

    The firts I want to do, is port the player.(iM USING BOX2D)

    Code (CSharp):
    1. Create Event:
    2.  
    3. execute code:
    4.  
    5. /// Set Fixed rotation && Stats
    6. event_inherited();
    7. hp = 5;
    8. spd = 0.15;
    9. hspd = 0;
    10. vspd = 0;
    11. xaxis = 0;
    12. yaxis = 0;
    13. len = 0;
    14. dir = 0;
    15. attacked = false
    16. image_speed = 0;
    17. scr_get_input_player1();
    18. [
    19.  ///scr_get_input_player1
    20. right_key = keyboard_check(ord("D"));
    21. left_key = keyboard_check(ord("A"));
    22. up_key = keyboard_check(ord("W"));
    23. down_key = keyboard_check(ord("S"));
    24. dash_key = keyboard_check_pressed(vk_space);
    25. attack_key = keyboard_check_pressed(ord("E"));
    26. switch_weapon = keyboard_check_pressed(vk_tab);
    27. use_weapon = keyboard_check(ord("Q"));
    28. start = keyboard_check_pressed(vk_escape);
    29.  
    30. //get the axis
    31. xaxis = (right_key - left_key);
    32. yaxis = (down_key - up_key);
    33.  
    34. //Check for gamepad input
    35. if(gamepad_is_connected(0)) {
    36.    gamepad_set_axis_deadzone(0, .5);
    37.    xaxis = gamepad_axis_value(0, gp_axislh);
    38.    yaxis = gamepad_axis_value(0, gp_axislv);
    39.    dash_key = gamepad_button_check_pressed(0, gp_face1);
    40.    attack_key = gamepad_button_check_pressed(0, gp_face3);
    41.    switch_weapon = gamepad_button_check_pressed(0, gp_face4);
    42.    use_weapon = gamepad_button_check(0,gp_shoulderrb);
    43.    start = gamepad_button_check_pressed(0,gp_start);
    44. }
    45.    
    46. ]
    47.  
    48. state = scr_move_state_player1;
    49. [
    50. ///scr_move_state_player1
    51.  
    52. scr_get_input_player1();
    53.  
    54. if (dash_key && obj_player_stats.stamina >= DASH_COST) {
    55.    state = scr_dash_state;
    56.    alarm[0] = room_speed/6;
    57.    obj_player_stats.stamina -= DASH_COST;
    58.    obj_player_stats.alarm[0] = room_speed;
    59. }
    60.    
    61. if (attack_key && obj_player_stats.stamina >= ATTACK_COST && !use_weapon) {
    62.    image_index = 0;
    63.    state = scr_attack_state;
    64.    obj_player_stats.stamina -= ATTACK_COST;
    65.    obj_player_stats.alarm[0] = room_speed;
    66.    
    67. }  
    68.  
    69. if (use_weapon) {
    70.  
    71. if (attack_key)
    72.    {
    73.    
    74.    }
    75. }
    76. //Get Direction
    77. dir = point_direction(0,0, xaxis, yaxis);
    78.  
    79. //Get the length
    80. if (yaxis == 0 && xaxis == 0) {
    81.     len = 0;
    82. } else {
    83.    len = spd;
    84.    //lenx = spd*xaxis;
    85.    //leny = spd*yaxis;
    86.    scr_get_face();
    87. }
    88.  
    89. // Get hspd and vspd
    90. hspd = lengthdir_x(len, dir);
    91. vspd = lengthdir_y(len, dir);
    92.  
    93. //Move
    94. if (!use_weapon) {
    95. phy_position_x += hspd+(xaxis/2);
    96. phy_position_y += vspd+(yaxis/2);
    97. }
    98.  
    99. //Control the sprite
    100. image_speed = .1;
    101. if (len == 0 ) image_index = 0;
    102.  
    103. switch (face) {
    104.      
    105.      case RIGHT:
    106.        sprite_index = spr_player_right
    107.        break;
    108.      
    109.      case UP:
    110.        sprite_index = spr_player_up
    111.        break;
    112.      
    113.      case LEFT:
    114.        sprite_index = spr_player_left
    115.        break;
    116.      
    117.      case DOWN:
    118.        sprite_index = spr_player_down
    119.        break;
    120.      }
    121.        
    122. ]
    123. face = DOWN;
    124.  
    125. //Iventory
    126. for(var i = 0; i<=1; i++) {
    127.         inv[ i ] = -1;
    128.         inv_number[ i ] = 0;
    129. }
    130.  
    131.  
    132. Destroy Event:
    133.  
    134. execute code:
    135.  
    136. ///Death, Fade && Stop Vibration
    137. instance_create(x,y,obj_fade_out_game_end);
    138. instance_create(x,y,obj_player_death);
    139. gamepad_set_vibration(0, 0, 0);
    140.  
    141. Alarm Event for alarm 0:
    142.  
    143. execute code:
    144.  
    145. ///For dash state
    146. state = scr_move_state_player1;
    147.  
    148. Alarm Event for alarm 1:
    149.  
    150. execute code:
    151.  
    152. ///For death
    153.  
    154. Alarm Event for alarm 2:
    155.  
    156. execute code:
    157.  
    158. ///Collison with Door
    159.  
    160. Alarm Event for alarm 3:
    161.  
    162. execute code:
    163.  
    164. ///Stop vibration
    165. gamepad_set_vibration(0, 0, 0);
    166.  
    167. Step Event:
    168.  
    169. execute code:
    170.  
    171. ///Move player in step event
    172. depth = -y;
    173. script_execute(state);
    174.  
    175. //Check for death
    176. if (obj_player_stats.hp <= 0) {
    177.     instance_destroy()
    178.     }
    179.  
    180.  
    181.  
     
  2. Lemmings19

    Lemmings19

    Joined:
    Apr 22, 2015
    Posts:
    6
    Have you taken the time to go through the videos on C# scripting in Unity (though you can use Javascript or Boo if you prefer - Javascript would be much more similar to Game Maker language)? They will answer a lot of basic questions about features that exist in Unity that are equivalents for much of what you have done in GameMaker. Key bindings and input for example are covered in video #17: GetButton and GetKey.

    There are also other tutorials (such as this one) which are great for getting a basic understanding of Unity.

    How familiar are you with object oriented programming, C#, or Javascript?

    Please be specific with any problems you're facing, otherwise I am afraid that you won't find much help. Be specific about what you are struggling with, or what in particular you need help with.
     
  3. Blackgarden

    Blackgarden

    Joined:
    Oct 23, 2015
    Posts:
    11
    Do you know how I can modify an object depth in unity(without using z)?
     
  4. Storyteller

    Storyteller

    Joined:
    May 15, 2012
    Posts:
    23
    um. you should read the documentation.

    Start with Input.GetKey

    much of your trouble may be solved there, but you really need to get used to the unity workflow.

    Good Luck
     
  5. Lemmings19

    Lemmings19

    Joined:
    Apr 22, 2015
    Posts:
    6
    Sorting layers will probably be the answer you are looking for.