-1
\$\begingroup\$

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

\$\endgroup\$
7
  • 1
    \$\begingroup\$ possible duplicate of How do I make a vehicle move to a point and stop without overshooting or oscillating? \$\endgroup\$ Commented Jul 12, 2015 at 22:50
  • \$\begingroup\$ @SethBattin i dont care about stopping at the point, just moving to it, final velocity is irrelevant for this problem \$\endgroup\$
    – t123
    Commented Jul 12, 2015 at 22:51
  • \$\begingroup\$ Can you clarify what you meant by "doughhnut", then? That made me imagine that you were trying to stop at a point and wrongly orbiting it briefly. Or as that duplicate described it, oscillating. \$\endgroup\$ Commented Jul 12, 2015 at 22:53
  • \$\begingroup\$ @SethBattin added a couple of images \$\endgroup\$
    – t123
    Commented Jul 12, 2015 at 23:04
  • 2
    \$\begingroup\$ Needs clarification for "natural" and "human-like". Nobody agrees on their meanings. \$\endgroup\$
    – Anko
    Commented Jul 12, 2015 at 23:17

2 Answers 2

0
\$\begingroup\$

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

\$\endgroup\$
0
\$\begingroup\$

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;
\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .