J
jiminy123
Guest
I have put a chest in my game, when opened it drops potions and gold. I am trying to make them spawn randomly around the chest when opened but they always spawn in the same place.
this is the code I am using for when the player presses "F" near the chest.
if (distance_to_object(oPlayer) < 32 ) and (image_index = 0)
{
image_index = 1;
instance_create_layer(x+-irandom_range(48,64),y+-irandom_range(48,64), "Objects", oHpPotion);
instance_create_layer(x+-irandom_range(48,64),y+-irandom_range(48,64), "Objects", oManaPotion);
instance_create_layer(x+-irandom_range(48,64),y+-irandom_range(48,64), "Objects", oCoin);
}
I have randomize(); in the create event for the chest, have tried putting it in the keyboard check event and in a step event. Items always spawn in the same place on top of each other.
this is the code I am using for when the player presses "F" near the chest.
if (distance_to_object(oPlayer) < 32 ) and (image_index = 0)
{
image_index = 1;
instance_create_layer(x+-irandom_range(48,64),y+-irandom_range(48,64), "Objects", oHpPotion);
instance_create_layer(x+-irandom_range(48,64),y+-irandom_range(48,64), "Objects", oManaPotion);
instance_create_layer(x+-irandom_range(48,64),y+-irandom_range(48,64), "Objects", oCoin);
}
I have randomize(); in the create event for the chest, have tried putting it in the keyboard check event and in a step event. Items always spawn in the same place on top of each other.
Last edited by a moderator: