• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GML cant find way back RTS

S

Swegm

Guest
Hi!

I have a problem wich i have solved before but cant remember how i did that.
Problem is my unit goes gathering resources
when he will go back to his house delivering the resources
he just runs around and can't find the way back. (He also seems to double the speed)

my code looks like this


var goto_res
goto_res = instance_nearest(x,y,obj_resource)
var goto_house
goto_house = instance_nearest(x,y,obj_house)

while obj_house goto_tree = true && carry = 0
{
mp_potential_step(goto_res.x,goto_res.y,movespeed,true)
}
// resource gather
if place_meeting(x+2,y+2,obj_resource) && carry = 0
{
carry = carryMax
}
if carry = carryMax
{

mp_potential_step(goto_house.x,goto_house.y,movespeed,true)

}
if place_meeting(x+2,y+2,obj_house) && carry = carryMax
{
carry = 0
}
 
Last edited by a moderator:
S

Swegm

Guest
I understand the problem now but can't solve it, please help. it must be my While function that mess it all up :(
 
J

Jdown79

Guest
AFAIK you're moving twice as fast because your diagonal speed is faster than your horizontal, debug it to confirm


/// draw event
var dis = abs(x - xprevious);
draw_text(view_xview + 20, view_yview + 20, "realSpd: " + string(dis));
 
S

Swegm

Guest
AFAIK you're moving twice as fast because your diagonal speed is faster than your horizontal, debug it to confirm


/// draw event
var dis = abs(x - xprevious);
draw_text(view_xview + 20, view_yview + 20, "realSpd: " + string(dis));
yeah maybe thats why. but my problems solved when i delete the code where the WHILE function starts.. i cant understand how to fix this.. cause i need that while

anyway thanks for the answer
 
J

Jdown79

Guest
Code:
while obj_house goto_tree = true
is this formatted right?

What are you saying here? while obj_house exists?
Code:
while(object_exists(obj_house))
{
if goto_tree = true && carry = 0
{

}
}
I'm no expert but that while statement looks wrong to me, explain what you want that while to do?
 
Top