Computer Science Canada

help with 'tracking'

Author:  Chaos_Theory [ 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?

Author:  Token [ Thu Apr 21, 2005 3:01 pm ]
Post 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)


: