if BugType = 1 if instance_exists(Obj_Food_Small)move_towards_point(Obj_Food_Small.x, Obj_Food_Small.y, 3) rather move_towards_point(Obj_Ant_Home.x, Obj_Ant_Home.y, 3);And I desire it to test if over there is a food object and also if over there is move towards the food which transforms the pest type into 2 and also then the ant will go ago to the home, except the ant when produced just move to the right, where there isn"t any kind of food.Thanks if anyone have the right to help.

You are watching: Game maker studio move towards object


You have one too many brackets. I"ve eliminated the extract bracket and formatted and readjusted the code. Rather of checking if BugType is 1 or 2 i recommend just assigning it 1 or 0 once there is food and if there isn"t.


A boolean is merely a value that have the right to either be true or false. Note that at this time GameMaker: Studio go not assistance "true" boolean values, and also actually accepts any kind of real number listed below 0.5 as a false value, and also any actual number same to (or better than) 0.5 as being true.

So you can just check if BugType is true(0.5 or greater) or false(less than 0.5).

if (BugType){ if instance_exists(Obj_Food_Small) BugType = 1; move_towards_point(Obj_Food_Small.x, Obj_Food_Small.y, 3) else BugType = 0; move_towards_point(Obj_Ant_Home.x, Obj_Ant_Home.y, 3);
improve this price
answered might 20 "19 at 0:20


1191212 bronze title
include a comment |
There"s two things going ~ above here! solving the very first should solve the second.

First is that you to speak it turns into an insect type 2 prior to returning home, currently if us look in ~ the password we check out that move_towards_point(Obj_Ant_Home.x, Obj_Ant_Home.y, 3); is in reality within the limit of if BugType = 1 {.

So when the bug gets to the food, they become BugType 2, and also then your password to return home never actually runs.

See more: Rare Non Legendary Pokemon In Emerald ? Pokemon Emerald Legendaries

so 2nd thing:

The reason your ant keeps on moving is likely because move_towards_point() actually transforms the object"s integrated speed variable, which is most likely never being set back come 0. SO, as soon as BugType becomes 2, the return house code doesn"t run, and also the pest continues along at the rate they were last going.

all the to to speak you could want something prefer this:

if (instance_exists(Obj_Food_Small)) BugType = 1; move_towards_point(Obj_Food_Small.x, Obj_Food_Small.y, 3)else BugType = 2; move_towards_point(Obj_Ant_Home.x, Obj_Ant_Home.y, 3);but the vital thing is no to have actually the return residence code in one area that is only executed as soon as the pest is in "go gain food" mode