I just had a play around and a brush up on Sin and Cos etc and have learned and refreshed a lot. I have a slightly better understanding but some things are still puzzling me regarding this bit.
rem draw circles and update position to move towards target
for i = 1 to humanCount
rem if circle is more than a movement step away from target, move towards target
if ((person(i).xpos-person(i).targetX)^2 + (person(i).ypos-person(i).targetY)^2) > speed*speed
a# = atanfull(person(i).targetX - person(i).xpos, person(i).targetY - person(i).ypos)
person(i).xpos = person(i).xpos + sin(a#)*speed
person(i).ypos = person(i).ypos + cos(a#)*speed
rem show line from circle to target
ink rgb(0,255,0),0
line person(i).xpos, person(i).ypos, person(i).targetX, person(i).targetY
endif
rem draw circles
ink rgb(255,255,255),0
circle person(i).xpos, person(i).ypos, 5
next i
Note: Deliberately quoting code not codeboxing for ease of reading.
Quote: "
if ((person(i).xpos-person(i).targetX)^2 + (person(i).ypos-person(i).targetY)^2) > speed*speed
"
Im not too sure
how exactly this works. I know
what its doing as if its not at that position then (do rest of code which moves it). Particularly not sure why the > speed*speed thing.
Quote: "
a# = atanfull(person(i).targetX - person(i).xpos, person(i).targetY - person(i).ypos)
"
Now this line is just making the next ones work because it saves typing that code again, instead you just put a# but even though i have read how atanfull works i still dont understand it and therefore dont know exactly what this statement is saying.
Quote: "
person(i).xpos = person(i).xpos + sin(a#)*speed
person(i).ypos = person(i).ypos + cos(a#)*speed
"
Again now i think i know what this is doing, its the part that updates the x and y pos and moves it using speed but because i dont understand why the angle*speed moves it or how the angle is worked out using atanfull then adding that to sin or cos im a bit stuck. Now what i am also missing from this is why sin and cos are the other way round. I though cos was for xpos and sin would be for ypos yet person(i).xpos + sin(a#) ? not cos(a#) i dont know.
Now dont get me wrong, using this im pretty sure i could make something where a "building" is placed down which automatically has a co-ordinate where its "entrance" is. Then make a "human" walk from its designated point to the entrance of that building and in fact pretty much wherever i like, be it a random place, a specified place or a mouseclick etc. I would just like to try and understand it deeper if anyone can help please.