D
designer
Guest
I try to create a NPC, randomly roaming on the grid, actually nothing fancy.
NPC should choose a random direction(up, down, left, right) and go 64 pixels (gridsize) to this direction.
Teleporting to the position isn't quite difficult, .... moving however ...
I tried with 'move_to_this_direcion' but it wont work with 'move_snap'.
Can anybody give me a little hint, how to get it to work?
NPC should choose a random direction(up, down, left, right) and go 64 pixels (gridsize) to this direction.
Teleporting to the position isn't quite difficult, .... moving however ...
I tried with 'move_to_this_direcion' but it wont work with 'move_snap'.
Can anybody give me a little hint, how to get it to work?
Code:
//COUNTDOWN
if count //count down
{
countdown--;
while(countdown < 0)
{
countdown = 60;
}
if (countdown = 0) //if countdown is 0, second timer starts counting
{
{
timer--;
while(timer < 0){timer = 2};
}
}
}
//RANDOM NUMBER
if (timer = 0) //if timer is 0, pause counting and choose random number between 0 and 3
{
count = false
rand_numb = choose(round(irandom_range(0, 10)));
if (rand_numb >=0 && rand_numb <=3)
{
count = true; //if number is choosen, restart counting
start_moving = true;
}
}
//MOVING
if (start_moving && timer = 1) //if count reaches 1, pause counting again and start to move
{
count = false;
switch(rand_numb)
{
case 0: if place_free(x-64,y){ x-=64} start_moving = false; count = true; break;
case 1: if place_free(x+64,y){ x+=64} start_moving = false; count = true; break;
case 2: if place_free(x,y+64){ y+=64} start_moving = false; count = true; break;
case 3: if place_free(x,y-64){ y-=64} start_moving = false; count = true; break;
} move_snap(64,64);
}
//BACKUP OF NOT WORKING CONCEPT
/* ---not working concept
if (choosen_number && timer = 1)
{
count = false;
switch(rand_numb)
{
case 0: if place_free(x-64,y) && point_distance(x,y,x-64,y)>4 {move_towards_point(x-64,y, 4);}else {speed = 0; choosen_number = false; count = true;} break;
case 1: if place_free(x+64,y) && point_distance(x,y,x+64,y)>4 {move_towards_point(x+64,y, 4);}else {speed = 0; choosen_number = false; count = true;} break;
case 2: if place_free(x,y+64) && point_distance(x,y,x,y+64)>4 {move_towards_point(x,y+64, 4);}else {speed = 0; choosen_number = false; count = true;} break;
case 3: if place_free(x,y-64) && point_distance(x,y,x,y-64)>4 {move_towards_point(x,y-64, 4);}else {speed = 0; choosen_number = false; count = true;} break;
default: speed = 0; move = false; count = true; break;
} move_snap(64,64);
}
Last edited by a moderator: