C
Carcophan
Guest
Hello everyone.
I have some code that is triggered from a collision event.
When the player interacts with the 'quest item' in one location, it should spawn a 'key' in a new random-ish location (a small confined area, versus just going any where).
Problem seems to be that the key is spawning on top of existing walls and other objects sometimes, instead of in an open available space/tile. In one case the key spawned ON the chest itself and was unobtainable.
This leads me to believe that the code below just happens to work sometimes and is in fact wrong in some way.
Is it okay that the code below exists only in the 'obj_quest' on-collision event? Should it live somewhere else, or should I be attempting another route?
Thanks all!
I have some code that is triggered from a collision event.
When the player interacts with the 'quest item' in one location, it should spawn a 'key' in a new random-ish location (a small confined area, versus just going any where).
Problem seems to be that the key is spawning on top of existing walls and other objects sometimes, instead of in an open available space/tile. In one case the key spawned ON the chest itself and was unobtainable.
This leads me to believe that the code below just happens to work sometimes and is in fact wrong in some way.
Is it okay that the code below exists only in the 'obj_quest' on-collision event? Should it live somewhere else, or should I be attempting another route?
Code:
var ranKeyLocXX = irandom_range((global.mazeWidth div 2),global.mazeWidth - 3), ranKeyLocYY = irandom_range((global.mazeHeight div 2),global.mazeHeight - 3);
while ( !global.grid [# ranKeyLocXX, ranKeyLocYY] &&
!position_meeting(ranKeyLocXX, ranKeyLocYY, obj_Chest) ) {
ranKeyLocXX = irandom_range((global.mazeWidth div 2),global.mazeWidth - 3);
ranKeyLocYY = irandom_range((global.mazeHeight div 2),global.mazeHeight - 3);
}
instance_create_depth(ranKeyLocXX * global.tileSize + (global.tileSize div 2), ranKeyLocYY * global.tileSize + (global.tileSize div 2), -10, obj_Key01);
Thanks all!