Computer Science Canada

Follow Procedure

Author:  Poutine King [ 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.

Author:  McKenzie [ Wed May 12, 2004 11:25 am ]
Post 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 B-Line for the first

Author:  Poutine King [ Thu May 13, 2004 10:04 am ]
Post subject: 

b.) I want one creature to catch the other ie intercept it.

An example of a procedure that does it would be perfect

Author:  omni [ Thu May 13, 2004 3:20 pm ]
Post 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.

Author:  Tony [ Thu May 13, 2004 3:55 pm ]
Post subject: 

would you not just measure the angle between two objects and move in that direction? Confused

Author:  Poutine King [ Fri May 14, 2004 10:12 am ]
Post 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. Confused And I'm not too sure of how to measure the angle either.

Author:  Tony [ Fri May 14, 2004 1:03 pm ]
Post subject: 

Poutine King wrote:
And I'm not too sure of how to measure the angle either.


tan = (y2-y1)/(x2-x1)

grade 10 math Rolling Eyes

Author:  Dan [ Fri May 14, 2004 1:29 pm ]
Post 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.

Author:  guruguru [ Fri May 14, 2004 8:30 pm ]
Post 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 Razz .

Author:  Tony [ Fri May 14, 2004 9:46 pm ]
Post subject: 

so apparently there's a topic on finding angle between two points floating around parallel to this

Author:  Poutine King [ Mon May 17, 2004 10:25 am ]
Post subject: 

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


: