Author 
Message 
Poutine King

Posted: Wed May 12, 2004 9:58 am Post subject: Follow Procedure 


I need a procedure to make one object follow another. An example would be appreciated. 





Sponsor Sponsor



McKenzie

Posted: Wed May 12, 2004 11:25 am Post subject: (No subject) 


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 BLine for the first 





Poutine King

Posted: Thu May 13, 2004 10:04 am Post subject: (No subject) 


b.) I want one creature to catch the other ie intercept it.
An example of a procedure that does it would be perfect 





omni

Posted: Thu May 13, 2004 3:20 pm Post subject: (No subject) 


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

Posted: Thu May 13, 2004 3:55 pm Post subject: (No subject) 


would you not just measure the angle between two objects and move in that direction? 
Tony's programming blog. DWITE  a programming contest. 




Poutine King

Posted: Fri May 14, 2004 10:12 am Post subject: (No subject) 


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

Posted: Fri May 14, 2004 1:03 pm Post subject: (No subject) 


Poutine King wrote: And I'm not too sure of how to measure the angle either.
tan = (y2y1)/(x2x1)
grade 10 math 
Tony's programming blog. DWITE  a programming contest. 




Dan

Posted: Fri May 14, 2004 1:29 pm Post subject: (No subject) 


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. 
Computer Science Canada
Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more! 




Sponsor Sponsor



guruguru

Posted: Fri May 14, 2004 8:30 pm Post subject: (No subject) 


To add to HackerDan's point.
code: 
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.
code: 
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 . 





Tony





Poutine King

Posted: Mon May 17, 2004 10:25 am Post subject: (No subject) 


Thanks for your help everyone! I have it working now and understand exactly what ya meant. Bye ofr now! 





