The Daily Click ::. Forums ::. Klik Coding Help ::. Move object from A to B in X time
 

Post Reply  Post Oekaki 
 

Posted By Message

vetmora120



Registered
  07/01/2010
Points
  273
13th September, 2013 at 13/09/2013 00:07:47 -

I have an object that I would like to move from point A to point B in X time. What is the formula to move it by to ensure it always gets to point B in X time?

The distance is 416 px and the time is 45000 "seconds".

 
n/a

hapsi



Registered
  13/11/2003
Points
  775
13th September, 2013 at 13/09/2013 12:11:50 -

Set speed: distance divided by seconds. I know it's really not that simple.. you have to adjust either the seconds or the distance to get it right, but once you do, it'll work on any distance or speed.

 
[Signature][/Signature]

Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1970

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
13th September, 2013 at 13/09/2013 15:04:30 -

As I'm sure you know, Speed = Distance / Time
You just need to get the time in frames rather than seconds:

Speed = Distance / ( Seconds * FramesPerSecond )

So to actually move an object, you could say:

+ Whenever...
-> Distance = Sqr((((Ax - Bx) pow 2) + ((Ay - By) pow 2))
-> Speed = Distance / (Seconds * FramesPerSecond)
-> MoveX = ((Bx - Ax) / Distance) * Speed
-> MoveY = ((By - Ay) / Distance) * Speed

+ Always
-> Add MoveX to XPos
-> Add MoveY to YPos
-> Set X position to XPos
-> Set Y position to YPos

 
n/a

vetmora120



Registered
  07/01/2010
Points
  273
14th September, 2013 at 14/09/2013 06:27:14 -

Thanks for your help, Sketchy. Can't seem to get that to work though.

I have the below. I've checked all the formula a few times. Note that Second is a global value and isn't supposed to be Seconds. All the alterable values are returning -1.#IND at runtime.

Image

 
n/a

vetmora120



Registered
  07/01/2010
Points
  273
14th September, 2013 at 14/09/2013 06:37:35 -

Hmm, I know the problem now is using relative X and Y coordinates so it's always at the same position within the window frame. Is there another way to do this? The context is a sun that moves upwards from the horizon from dawn to midday, if that helps.

 
n/a

hapsi



Registered
  13/11/2003
Points
  775
14th September, 2013 at 14/09/2013 12:00:43 -

Zero point is top left. So just reduce the x and y.

edit: okay, i see how dumb that sounds

Edited by hapsi

 
[Signature][/Signature]
   

Post Reply



 



Advertisement

Worth A Click