Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Follow Procedure
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Poutine King




PostPosted: 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
Sponsor
sponsor
McKenzie




PostPosted: 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




PostPosted: 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




PostPosted: 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




PostPosted: 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? Confused
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Poutine King




PostPosted: 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. Confused And I'm not too sure of how to measure the angle either.
Tony




PostPosted: 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)

grade 10 math Rolling Eyes
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Dan




PostPosted: 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
Sponsor
sponsor
guruguru




PostPosted: 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 Razz .
Tony




PostPosted: 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
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Poutine King




PostPosted: 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:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 11 Posts ]
Jump to:   


Style:  
Search: