Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Travelling along a hypotenuse

Chaz Longstaff
Registered User
Join date: 11 Oct 2006
Posts: 685
04-07-2008 20:02
I'm crappy at this kind of math.

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 + .08) 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.
Johan Laurasia
Fully Rezzed
Join date: 31 Oct 2006
Posts: 1,394
04-07-2008 23:19
Part of your problem is that llMoveToTarget () has no 'speed' control, the only parameters are vector and tau. Tau is the number of seconds it will take to get between the start position (where the car is at when llMoveToTarget() is executed), and the vector parameter inside the function. The speed of the movement is critically damped (reduction in velocity) across tau seconds. So, to control the speed, you adjust the start and end vector locations. Moving the vectors farther apart will cause the object to move faster, closer vectors, slower. If you need to say, slow down the cars 'speed', you'll need to have multiple target points along the cable. Now, a problem with multiple target points is that the car will have a tendency to slow down (damp) as it approaches the target, then burst forward towards the next target, causing a non uniform movement, which is not paticularly desirable in a cable car. So, what you can do to adjust for that is to set a longer range in the llTarget() function so that the at_target event triggers before the car slows down too much.

Hope that helps.
Chaz Longstaff
Registered User
Join date: 11 Oct 2006
Posts: 685
04-08-2008 15:46
Johan, I think you've just written one of the clearest, most coherent, most plain English explanations of that that I've yet seen. Thank you for that -- explains part of it anyway, as you say!
Johan Laurasia
Fully Rezzed
Join date: 31 Oct 2006
Posts: 1,394
04-09-2008 21:47
heh, oh geez (/me blushes). No problem. Glad to help... I created a pretty interesting security bot that follows a set path for a customer once. You set various waypoints in a notecard, then start it, and it moves from waypoint to waypoint. On top of that, if it comes within 10 meters of an avatar, it breaks off of it's set patrol path, approaches the avatar, greets them, (scans them with a laser beam), and then returns to his patrol path. It was quite a challenge to script, and took about two weeks to finish, but that's where I got so intimate with llMoveToTarget(). If anyone wants to stop by and check it out, I use one as a greeter in my main store in Midas Northwest, just search ClockWerks in the search, and teleport to my store in Midas NW.

I eventually plan to release it as a for-sale item eventually, but I want to change it from reading waypoints from a notecard (very tedious to setup, especially if there's many waypoints), and just have it so you can set it at a waypoint, and push a menu button. It'll store the waypoints in the object description for data persistence. Also, I want it to be able to find it's way back to the start position, or it's last waypoint if the sim reboots, so it'll be totally autonomous should the sim go down. At the moment, he just 'boots up' and waits to be started, so there's a few different things yet to hammer out with it. It also does a custom greet including usage of the avatar's name.
Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
10-26-2008 12:15
i'm not in world to go look for it right now. did you release this for sale? is it the bot you sold or the script? i'm interested in using the script in a product i'd like to sell
_____________________
Dark Heart Emporium

http://www.xstreetsl.com/modules.php?name=Marketplace&MerchantID=133020

want more layers for tattoos, specifically for the head? vote here
http://jira.secondlife.com/browse/VWR-1449?

llDetectedCollision* Functions similar to touch
http://jira.secondlife.com/browse/SVC-3369