
-----------------------------------
Poutine King
Wed May 12, 2004 9:58 am

Follow Procedure
-----------------------------------
I need a procedure to make one object follow another.  An example would be appreciated.

-----------------------------------
McKenzie
Wed May 12, 2004 11:25 am


-----------------------------------
What do you mean by "follow"?
a) follow the leader, where the second object takes the exact path
b) The second object tries to intercept, i.e. does a B-Line for the first

-----------------------------------
Poutine King
Thu May 13, 2004 10:04 am


-----------------------------------
b.) I want one creature to catch the other ie intercept it.

An example of a procedure that does it would be perfect

-----------------------------------
omni
Thu May 13, 2004 3:20 pm


-----------------------------------
well what you would do is have some if conditions comparing the coordinates of the predator with the prey and move the predator according to where the prey is.

-----------------------------------
Tony
Thu May 13, 2004 3:55 pm


-----------------------------------
would you not just measure the angle between two objects and move in that direction? :?

-----------------------------------
Poutine King
Fri May 14, 2004 10:12 am


-----------------------------------
I want to make one go to the other position but I don't know how to do it.  I know I should make the preditor follow the preys position I dojn't know how though. :? And I'm not too sure of how to measure the angle either.

-----------------------------------
Tony
Fri May 14, 2004 1:03 pm


-----------------------------------
And I'm not too sure of how to measure the angle either.

tan = (y2-y1)/(x2-x1)

grade 10 math :roll:

-----------------------------------
Dan
Fri May 14, 2004 1:29 pm


-----------------------------------
or you could go the real easy way of just checking if the thing you are going after is to the left or right of you then moving that way and if it is above or below you and going that way. It whould not be as accrite or as good as using math but it whould be very easy to understand and code.

-----------------------------------
guruguru
Fri May 14, 2004 8:30 pm


-----------------------------------
To add to HackerDan's point.


var personX, personY, chaserX, chaserY : int

...make person move...

if personX > chaserX then
    chaserX += 5
else
    chaserX -= 5
end if

if personY > chaserX then
    chaserY += 5
else
    chaserY -= 5
end if


Thats a really simple yet effective way.

Then to find angle you can use trig. Find the x distance away and y distance away.


var xDistance, yDistance, angle : int

xDistance := personX - chaserX
yDistance := personY - chaserY

angle := tan (yDistance / xDistance)


Then you can think of a way to move the person by the angle  :P .

-----------------------------------
Tony
Fri May 14, 2004 9:46 pm


-----------------------------------
so apparently there's a topic on [url=http://www.compsci.ca/v2/viewtopic.php?t=4805]finding angle between two points floating around parallel to this

-----------------------------------
Poutine King
Mon May 17, 2004 10:25 am


-----------------------------------
Thanks for your help everyone!  I have it working now and understand exactly what ya meant.  Bye ofr now!
