Ai pathing going nowhere, litteraly (gamemaker studio)

gamemaker-studio

#1

I need a little bit of help on my personnal project: Feast of the greedy.

It seems like i made a partially viable code on game maker, let me explain my reasonning.

i set up variables relating to the position of the objective and the floor one need to go
patrol = 100 (never change for now)
objective = 0
objectiveX = 0
objectiveY = 0
patrol_floor = 5 (this is the default value it returns too since 0 is the ground floor)

//chosing objective (1:patrol)(2:eat)(3:rest)
if objective = 0
{
if patrol > 99
{
objective = 1
}
else
{
if hungry > 50
{
objective = 2
}
else
objective = 3
}
}

Now we reach the problematic code

if objective = 1 && patrol_floor =5
{
patrol_floor = irandom(3)
global.patrol_floor = patrol_floor
if patrol_floor == 0
{
objectiveY = Obj_locationWaypoint1.y
objectiveX = Obj_locationWaypoint1.x
}
if patrol_floor == 1
{
objectiveY = Obj_locationWaipoint2.y
objectiveX = Obj_locationWaipoint2.x
}
if patrol_floor == 2
{
objectiveY = Obj_locationWaipoint3.y
objectiveX = Obj_locationWaipoint3.x
}
if patrol_floor == 3
{
objectiveY = Obj_locationWaipoint4.y
objectiveX = Obj_locationWaipoint4.x
}
}

this part generate a random number (it works)
in order to tell what waypoint location to use for later code.
the part after this is supposed to tell where to move in order to reach teleporters (in working condition).
adding ! (not) to the second part of the condition relating to if the waypoint position corelate with the one given in advance (yes there is a typo in waypoint, but its not the problem) will cause an endless movement in the given position. Currently the Ai stand still and doesn’t go anywhere.

//time to go about the building
//walking
if objectiveY < y or objectiveY > y
{
if Obj_locationWaypoint1.y = y && Obj_locationWaipoint4 = objectiveY
{
hsp= movespeed
}

if Obj_locationWaypoint1.y = y && Obj_locationWaipoint3 = objectiveY
{
hsp= -movespeed
}

if Obj_locationWaypoint1.y = y &&  Obj_locationWaipoint2 = objectiveY
{
hsp= -movespeed
}

if Obj_locationWaipoint2.y = y && Obj_locationWaypoint1 = objectiveY
{
hsp= -movespeed
}

if Obj_locationWaipoint2.y = y && Obj_locationWaipoint3 = objectiveY
{
hsp= movespeed
}

if Obj_locationWaipoint2.y = y && Obj_locationWaipoint4 = objectiveY
{
hsp= movespeed
}

if Obj_locationWaipoint3.y = y && Obj_locationWaipoint2 = objectiveY
{
hsp= movespeed
}

if Obj_locationWaipoint3.y = y && Obj_locationWaypoint1 = objectiveY
{
hsp= movespeed
}

if Obj_locationWaipoint3.y = y && Obj_locationWaipoint4 = objectiveY
{
hsp= -movespeed
}

if Obj_locationWaipoint4.y = y && Obj_locationWaypoint1 = objectiveY
{
hsp= movespeed
}

if Obj_locationWaipoint4.y = y && Obj_locationWaipoint3 = objectiveY
{
hsp= -movespeed
}

if Obj_locationWaipoint4.y = y && Obj_locationWaipoint2 = objectiveY
{
hsp= -movespeed
}

}

well if anything i may need to just change completely my code if i can’t fix it :frowning:
Well i hope all your projects will go smoothly.


#2

It looks like you’re comparing a vector to an integer, which is probably making gamemaker unhappy.

Everywhere you have something like this:

if Obj_locationWaypoint1.y = y && Obj_locationWaipoint4 = objectiveY

You’ll want to make it like this:

if Obj_locationWaypoint1.y = y && Obj_locationWaipoint4.y = objectiveY

The difference is the “.y” at the end of “Obj_locationWaipoint4”.


#3

facepalm

its like an oversight on my part. coded that today and my mind wasn’t fresh enough to realise it. going to check it.
I omitted the reset code, but if everything work my Ai will try to patrol different floors.


#4

well now the Ai did move… then somehow failed and got stuck within the teleporter. thanks for unstucking me. still got to make sure the transistion between floors goes well. if i hit anymore walls i will make sure to say it.

thanks you heavy heretic