• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Newbie in GML (i need help)

F

Farokh-fakhar

Guest
Hi! im new with gamemaker studio2 and programming but i was hoped you guys could help me

right now im trying to prototype a mechanic.

i want to my player object Suction/Pull other objects like boxes to it self and destroy them.

it could realy help me if you guys tell me what i need to read do this code

right now im trying to do it some how with gravity/place_meeting

thank you <3
 
F

FuRyvok

Guest
So, you will need a player Obj and a box Obj

you have to add this code in the Box Step event

Code:
//If The player is in the collision circle
if(collision_circle(x, y, 400, oBox, false, false)){
    //And if the player Press SPACE bar
    if(keyboard_check(vk_space)){
        //The Box will move to the Player
        move_towards_point(oPlayer.x,oPlayer.y,4);
    }
}
if you want to see the collision circle in this example the circle has a 400pixel radius
You will need a Draw Event at the Box Obj
Code:
draw_self();
draw_circle(x,y,400,true);
You have to also add a Collision Event with player to the box Obj, and there you have to type
Code:
instance_destroy();
 
F

Finn

Guest
Performance wise it is better to put the code into the player to only have one object check for collision for instance in case you have multiple boxes in a room.
Its also great to check the space key first and only then check if the player is pushing against a box.
 
F

Farokh-fakhar

Guest
Performance wise it is better to put the code into the player to only have one object check for collision for instance in case you have multiple boxes in a room.
Its also great to check the space key first and only then check if the player is pushing against a box.
thanks , yes i did what you said . it help a lot
So, you will need a player Obj and a box Obj

you have to add this code in the Box Step event

Code:
//If The player is in the collision circle
if(collision_circle(x, y, 400, oBox, false, false)){
    //And if the player Press SPACE bar
    if(keyboard_check(vk_space)){
        //The Box will move to the Player
        move_towards_point(oPlayer.x,oPlayer.y,4);
    }
}
if you want to see the collision circle in this example the circle has a 400pixel radius
You will need a Draw Event at the Box Obj
Code:
draw_self();
draw_circle(x,y,400,true);
You have to also add a Collision Event with player to the box Obj, and there you have to type
Code:
instance_destroy();
Thanks it help a lot <3
 
Top