-1

I am having trouble moving an object to a target position with a maximum acceleration limit.

If i just accelerate towards the target the object will fly in a doughnut a few times before hitting the target. example

If i first accelerate to reduce the vector rejection i get a nasty path directly away from the target and then a line straight to the target. example

Any ideas how to move in a natural human-like path?

edit

I now move in a circle at current speed with maximum acceleration until i am facing the target then accel towards it example1 example2

its not perfect but its quite predictable for players and i can calcuate time to reach target in constant time now (yey)

if anyone wants a break down of the math i can explain

t123
  • 703
  • 1
  • 7
  • 18

2 Answers2

0

You could try setting a threshold from the target, and multiplying the object's speed by distance / threshold:

acceleration = distance / threshold

if (acceleration <= 1) {
    speed *= acceleration;
}

Here's an interactive example I threw together quickly:

https://dl.dropboxusercontent.com/u/38185080/Flash/Examples/Deceleration.swf

Checking gradual movement will set speed to the acceleration value regardless of whether or not it is a value less than one. Without it checked, the speed will always equal the max speed unless it is within the threshold - it uses the same code displayed above, slightly modified:

if (gradual) {
    speed = acceleration;
} else {
    speed = maxSpeed;

    if (acceleration <= 1) {
        speed *= acceleration;
    }
}

Now you all you do is add the object direction to its position and multiply it by speed:

position += direction * speed;
driima
  • 995
  • 4
  • 23
0

If you don't need a strictly physics based solution, bias and gain can be great for giving a nice organic (accel / decel) feel to a simple linear interpolation.

http://blog.demofox.org/2012/09/24/bias-and-gain-are-your-friend/ http://demofox.org/biasgain.html

Alan Wolfe
  • 2,353
  • 1
  • 13
  • 30