Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki   Blog   Search   Turing   Chat Room  Members
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.

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 B-Line 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 = (y2-y1)/(x2-x1)

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!

guruguru

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

 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

Posted: Fri May 14, 2004 9:46 pm   Post subject: (No subject)

so apparently there's a topic on finding angle between two points floating around parallel to this
Tony's programming blog. DWITE - a programming contest.
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!
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

Page 1 of 1  [ 11 Posts ]
 Jump to:  Select a forum  CompSci.ca ------------ - Network News - General Discussion     General Forums   -----------------   - Hello World   - Featured Poll   - Contests     Contest Forums   -----------------   - DWITE   - [FP] Contest 2006/2008   - [FP] 2005/2006 Archive   - [FP] 2004/2005 Archive   - Off Topic     Lounges   ---------   - User Lounge   - VIP Lounge     Programming -------------- - General Programming     General Programming Forums   --------------------------------   - Functional Programming   - Logical Programming   - C     C   --   - C Help   - C Tutorials   - C Submissions   - C++     C++   ----   - C++ Help   - C++ Tutorials   - C++ Submissions   - Java     Java   -----   - Java Help   - Java Tutorials   - Java Submissions   - Ruby     Ruby   -----   - Ruby Help   - Ruby Tutorials   - Ruby Submissions   - Turing     Turing   --------   - Turing Help   - Turing Tutorials   - Turing Submissions   - PHP     PHP   ----   - PHP Help   - PHP Tutorials   - PHP Submissions   - Python     Python   --------   - Python Help   - Python Tutorials   - Python Submissions   - Visual Basic and Other Basics     VB   ---   - Visual Basic Help   - Visual Basic Tutorials   - Visual Basic Submissions     Education ----------- - Student Life   Graphics and Design ----------------------- - Web Design     Web Design Forums   ---------------------   - (X)HTML Help   - (X)HTML Tutorials   - Flash MX Help   - Flash MX Tutorials   - Graphics     Graphics Forums   ------------------   - Photoshop Tutorials   - The Showroom   - 2D Graphics   - 3D Graphics     Teams ------ - dTeam Public

 Style: Appalachia blueSilver eMJay subAppalachia subBlue subCanvas subEmjay subGrey subSilver subVereor Search: