sensodyne
Member
Hello everyone I used a few tutorials and made myself an object that the player can push.
I only miss two things to do.
1.the Hero pushes the object to the end of the room and then he should not push it any further .. both when it is on the left side of the room or the right side of the room
2.The hero should also be able to pull an object towards him and pull it
how to do it? My code looks like this
obj_chest
create
DnD blocks
Begin Step
collision with obj_ground, i.e. hard ground
collision with obj_hero
obj_hero
create
End Step
Thank you very much for any help
I only miss two things to do.
1.the Hero pushes the object to the end of the room and then he should not push it any further .. both when it is on the left side of the room or the right side of the room
2.The hero should also be able to pull an object towards him and pull it
how to do it? My code looks like this
obj_chest
create
DnD blocks
GML:
Set variable
Applies to
Self
Variable uboot
0
GML:
Set variable
Applies to
Self
Variable bul
0
Begin Step
GML:
///the moving box can be moved left and right
if place_meeting(x,y,obj_water)
{
uboot=1;
}
else
{
uboot=0;
}
//gravitation
if (place_free(x,y+2) && !place_meeting(x,y+10,obj_hero))
{
switch (uboot)
{
case 0:{gravity = 0.5;break;}
case 1:{gravity = 0.01;break;}
}
}
else {gravity = 0;}
gravity_direction = 270
///pushing the box by the player
if place_meeting(x-5,y,obj_hero) && keyboard_check(key.right) && place_free(x+2,y)
{
x+=2;
}
if place_meeting(x+5,y,obj_hero) && keyboard_check(key.left) && place_free(x-2,y)
{
x-=2;
}
collision with obj_ground, i.e. hard ground
GML:
if vspeed > 0 && !place_free(x,y+vspeed) {move_contact(270)}
vspeed = 0
gravity = 0
collision with obj_hero
GML:
if vspeed > 0 && !place_free(x,y+vspeed) {move_contact(270)}
vspeed = 0
gravity = 0
obj_hero
create
GML:
subtract = 0;
End Step
GML:
//animation for moving the chest by the hero
if in_AIR == false && (keyboard_check(key.right)) && (place_meeting(x-5,y,obj_chest) || place_meeting(x+5,y,obj_chest))
{sprite_index = spr_hero_moves_the_object; image_index = 23 -(subtract);
subtract -= 1; }
else if (keyboard_check(key.left)) && (place_meeting(x-5,y,obj_chest) || place_meeting(x+5,y,obj_chest)) {
sprite_index = spr_hero_moves_the_object; image_index = 23 -(subtract);
subtract -= 1; }
Thank you very much for any help