PDA

View Full Version : Smooth direct motion.



beefster09
01-20-2007, 12:27 AM
How do I make an object that moves directly towards a target in a Pythagorean-theorem-style speed? So instead of having a max in each direction, it would have a max in literal speed. So an object would travel at x degrees toward an object with z speed instead of moving in the 8 cardinal directions, being less direct.

Sorry if I've confused you, I got it from genetics.

Revfan9
01-20-2007, 12:37 AM
Hmm...

Not tested, but here is the way I think it could work.

Say that the FFC is at position 10,10 and the point you want to go to is 17,-8

10+8=18
10-17=-7

18/-7=-2.5714285714285714285714285714286

xspeed=1
yspeed=-2.5714285714285714285714285714286

Again, not sure if it will work, and it will be more difficult because the X/Y positions work as absolute values in the 4th quadrant, and negative values will almost never be used...

But try to build from that...

Or, as an alternate method, you could judge whether the position of the point is left/right/up/down and move accordingly. This script will not only follow a moving FFC, but it will also move in a straight line torwards a point.

beefster09
01-20-2007, 12:52 AM
I have an idea. It involves approximating ratios like what you suggested and bringing them down to size using the distance formula. (gee, I never knew my limited geometry knowledge would be this helpful!)

Saffith
01-20-2007, 02:00 AM
Yeah, that's pretty much it. It's basically xVel=speed*xDist/totalDist and yVel=speed*yDist/totalDist.