Making a cable car. Goes physical and goes up and down on an angled / inclined rope using llMoveTo(TargetVector, speed). This I'm calling the hypotenuse.
The angle of the incline on the hypotenuse will vary, I get it using this formula provided by Hewee Zetkin, many thanks.
float angleOfIncline(vector p1, vector p2) {
vector delta = p2-p1;
float len = llVecMag(delta);
if (len < 0.001) {
return 0.0;
}
return llAsin(delta.z/len);
}
It will move along the x axis and up the z axis at the same time; or backwards along the x axis and down the z axis at the same time.
I don't want it to move as fast up the z axis as it is along the x axis. X axis will always be longer by definition -- or else you have an elevator ;}
So I take the overall "speed" (say .6 metres) that is fed to llMoveTo as speed (or whatever the right word is) and make a special "speed" for the z axis by going:
float speedHeight = llFabs(speed * llFabs(myangle) );
Works like a charm going "up" (TargetVector.z + speedHeight), smooth as, er, well, and arrives right on target without deviating from a nice smooth angled ascent.
Coming down though (TargetVector.z - speedHeight) -- it hits its target z coordinate way too soon, and crawls along the ground on its belly till it hits its ultimate TargetVector.
I would have thought the same speedHeight adjustment would have worked in both directions, but hey, like I said, I'm lousy at this kind of math.
*And*, if I change the angle of the rise, making it more or less steep, going up I have to do adjustments like (TargetVector.z + speedHeight + .0
and going down, (TargetVector.z - speedHeight - .12) (for an incline that, using the above formula, reports as 0.780000.Okay, so as you see, I'm making a right mess of this. It's close in its movements, but no cigar yet. And I'd hate to have to do those extra adjustments each time the angle gets more or less steep. Erp.
So, um, help. I'm after a formula to adjust the z coord by, going up and going down, that will be a nice, flexible, non-hard-coded adjustment.