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

Username:   Password: 
 RegisterRegister   
 help with 'tracking'
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Chaos_Theory




PostPosted: Thu Apr 21, 2005 2:19 pm   Post subject: help with 'tracking'

how can I get an object on the screen to slowly move towards another object?

for example I have a bird that I want to slowly move towards a mouse on the screen... how do I do it?
Sponsor
Sponsor
Sponsor
sponsor
Token




PostPosted: Thu Apr 21, 2005 3:01 pm   Post subject: (No subject)

Well what you have to do is find the distance between you and the the ball and devide it by the number of pixels you want it to move each step, that becomes steps, then you take the diference of the mousey and bally and devide it by the steps, do the same for x, this gives you your rise and run, so then you add that step to the ballx and bally giving it a step of movement towards the mouse... somthing like this


code:

var mousex, mousey, speed : int
var steps, ballx, bally, rise, run: real

            steps := Math.Distance (ballx, bally, x, y - 10) / speed
            rise := ((mousey - bally) / steps)
            run := ((mousex - ballx) / steps)
            ballx += run
            bally += rise
           drawfilloval (round (ballx) , round (bally) , 10,10,red)
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  [ 2 Posts ]
Jump to:   


Style:  
Search: