Function moveTo(Vector3f vector)

Hi guys,

I make an easy game and I need to send my agent to concrete position. In jME I didn´t found any function to use, so I decided to create some by myself.

private void moveTo(Character a, float speed, Vector3f targetVector)
{
    Vector3f position = targetVector.subtract(a.getNode().getLocalTranslation());
    a.getControl().setWalkDirection(new Vector3f(position.getX()/speed, position.getY()/speed, position.getZ()/speed));
    a.getControl().setViewDirection(position);
}

It makes what I want, but problem is when character is yet near targetVector than character walks too slow. I need to character walks constantly all the time.

    a.getControl().setWalkDirection(new Vector3f(position.getX()/speed, position.getY()/speed, position.getZ()/speed));

this actually tell the character to move with the given speed and direction.
And your speed is based on the distance so… maybe try to use direction instead of position, using normalize().

Yep, as RatKod says…

To put that line another way, you are saying:
“Go the remaining distance but take ‘speed’ seconds to do it.”

So if ‘speed’ is 10 and you are 50 meters away then you are saying at various intervals:
“Go 50 meters but take 10 seconds to do it.”
“Go 49 meters but take 10 seconds to do it.”

“Go 1 meter but take 10 seconds to do it.”

See?

ok, thanks, i try it :slight_smile: