Author Topic: Using velocity to get from a point to another point? [Self-Fixed]  (Read 750 times)

How would I use %player.addVelocity(X Y Z); to get to one point to another?

See last post to see the fix, if you can find a shorter way, please tell me.
« Last Edit: November 21, 2013, 09:39:03 PM by Advanced Bot »

You mean to pass through a point? Or do you want to make them stop as soon as you get to the right place.

Either way, you'll need to find the vector difference between the two positions, normalize that, then scale it by the speed you want the player to fly at. If you want the player to stop where the second point is, you can either calculate it by using the speed you specify and then scheduling .setVelocity("0 0 0"). The problem with that is if the player is touching the ground or something is similarly in the way, the player won't stop at the correct spot. You could continously monitor their position and continually do the first step til you end up where you're supposed to.


%o = p(vis);
%p1 = %o.getPosition();
%p2 = nameToID("_cake").getPosition();
%vecSub = vectorSub(%p1,%p2); talk("%vecSub: " @ %vecSub);
%vecSc = vectorScale(%vecSub,5); talk("%vecSc: " @ %vecSc);
%vecAdd = vectorAdd(%vecSc,"0 0 10"); talk("%vecAdd: " @ %vecAdd);
%o.addVelocity(%vecAdd);


EDIT: Nevermind, it works.
EDIT2: Nevermind again, it doesn't work as I thought of it.
EDIT3: It works again, but it is throwing a lot of velocity, why?
EDIT4: Fixed. Here is the official code below.

%o = p(vis);
%p1 = %o.getPosition();
%p2 = nameToID("_cake").getPosition();
%p_1 = getWord(%p1,0)/10*-1 SPC getWord(%p1,1)/10*-1 SPC getWord(%p1,2);
%p_2 = getWord(%p2,0)/10*-1 SPC getWord(%p2,1)/10*-1 SPC getWord(%p2,2);
%o.addVelocity(vectorAdd(vectorScale(vectorSub(%p_1,%p_2),5),"0 0 10"));


Only way how it works.
« Last Edit: November 21, 2013, 09:33:10 PM by Advanced Bot »

Looks awfully overcomplicated.

%obj.setVelocity(vectorScale(vectorNormalize(vectorSub(<target>, %obj.getHackPosition())), <speed>));

Obviously, split it up over multiple lines if you want it to be readable.