A
Aaron Fryer
Guest
Hi Folks,
First time posting here so apologies if I do something wrong.
Ive just picked up GM after a couple of years with Construct 2 and am getting stuck with some of the GML. I'm very keen to complete my current project only using code, and I've run into an issue, that everyone I have asked cannot figure out either,
Basically, I have a sprite for an Impala, which I would like to visit an Acacia tree when it gets hungry, then to wander off in a random direction for 50-150 pixels (im not actually too fussed on the distrance, as long as its away from the tree)
I have tried multiple iterations of the below code, and copied many attempts from other posts i've already found, but every time the Impala visits the tree, it wanders off and doesn't stop.
If anyone could suggest a way to achieve my goal it would be awesome, The variables are all only in use locally so I dont need to use any of them - they can be removed/changed.
Thanks in advance,
Aaron
First time posting here so apologies if I do something wrong.
Ive just picked up GM after a couple of years with Construct 2 and am getting stuck with some of the GML. I'm very keen to complete my current project only using code, and I've run into an issue, that everyone I have asked cannot figure out either,
Basically, I have a sprite for an Impala, which I would like to visit an Acacia tree when it gets hungry, then to wander off in a random direction for 50-150 pixels (im not actually too fussed on the distrance, as long as its away from the tree)
I have tried multiple iterations of the below code, and copied many attempts from other posts i've already found, but every time the Impala visits the tree, it wanders off and doesn't stop.
Code:
if (hunger <=2){
newTarget = instance_nearest(x,y,obj_veg_Acacia);
if (newTarget != noone){
//image_angle = point_direction(x,y,newTarget.x,newTarget.y); //--------- Left out as not sure if want sprite to rotate
move_towards_point(newTarget.x,newTarget.y,3);
if (distance_to_object(newTarget)< 2){
with(newTarget){
portions = portions - 1;
}
hunger = 5;
restRange = 150;
restPointX = random_range(x-restRange,x+restRange);
restPointY = random_range(y-restRange,y+restRange);
if point_distance(x,y,newTarget.x,newTarget.y) < restRange {
move_towards_point(restPointX,restPointY,2);
}
else speed = 0;
}
}
Thanks in advance,
Aaron
Last edited by a moderator: