Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

llMoveToTarget in front of an object

Virrginia Tombola
Equestrienne
Join date: 10 Nov 2006
Posts: 938
06-07-2008 11:18
In the "How hard can this be?" category of questions, here I am demonstrating my complete lack of mathematical ability, I suspect.

I want an object to move along its local Z axis, in whatever direction it is pointed, but staying parallel to the ground (basically, making a fish people can sit on and steer, but control things can wait for later).

For testing purposes, I used a prim tapered on the Z axis, X axis pointed at the ground. On a touch, I wanted it to get its current position, then create a new position ten metres away on the z axis and start a MoveToTarget that way.


CODE

integer target;
float altitude=1;

default
{
state_entry()
{
llSetStatus(STATUS_PHYSICS, TRUE);
}

touch_start(integer total_number)
{

//Find out current rotation and sine/cosine of the angle of the global z axis thingee.
rotation rot=llGetRot();
vector ang=llRot2Euler(rot);
float cos= llCos(ang.z);
float sine=llSin(ang.z);
float abs= (ang.z/PI);
llOwnerSay("Angle is "+(string)abs+"PI");
llOwnerSay("Cosine is "+(string)cos);
llOwnerSay("Sine is "+(string)sine);

//Now, use that to get a new position in global coordinates. If my limited trig is right :P, sine is opposite over the hypotenuse, so that's the y axis displacement, x is the cosine.

vector pos =llGetPos();
llOwnerSay("position is "+(string)pos);
vector newpos = pos+<10*cos,10*sine,altitude>;

//Now move there
target=llTarget(newpos,1);
llMoveToTarget(newpos,3);
llLookAt(newpos,.1,.1);///keeps the object from wiggling as it moves
pos =llGetPos();
}

at_target(integer tnum, vector targetpos, vector ourpos)
{
//llOwnerSay("position is "+(string)ourpos); //Wow, that's a chatty event, turned that off....
llStopMoveToTarget();
llStopLookAt();
}
}



Really, I thought this would work, but it doesn't at all. I can get it to move back and forth nicely along one axis or another, but if I turn it to any non-cardinal heading, it seems rather random. Sometimes it just flips around.

I'm clearly doing something fundamentally wrong here. I mean, it is not even close to working. What am I missing?
_____________________


Horses, Carriages, Modern and Historical Riding apparel. Ride a demo horse, play whist, or just loiter. I'm fair used to loiterers.

http://slurl.com/secondlife/Caledon%20Eyre/48%20/183/23/
Dora Gustafson
Registered User
Join date: 13 Mar 2007
Posts: 779
06-07-2008 11:45
I would try this:
vector nose = llRot2Up( llGetRot()); // unit vector pointing the direction of the prims Z axis
...and...
vector newpos = pos+10.0*nose;
.. inserted on proper places in your program and replacing the values you have


(is that an answer to the question?)
_____________________
From Studio Dora
Virrginia Tombola
Equestrienne
Join date: 10 Nov 2006
Posts: 938
06-07-2008 12:35
Well, THAT works. I didn't know about llRot2Up :)

Still doesn't fix my difficulty with trigonometry, but high school is over a decade in my rear window now, thank goodness.
_____________________


Horses, Carriages, Modern and Historical Riding apparel. Ride a demo horse, play whist, or just loiter. I'm fair used to loiterers.

http://slurl.com/secondlife/Caledon%20Eyre/48%20/183/23/
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
06-07-2008 13:14
I would seriously advise against Euler angles for anything other than entering a simple rotation about one of the three primary axes, and even then llAxisAngle2Rot() is probably more intuitive and less prone to defects during code maintenance.

http://www.lslwiki.net/lslwiki/wakka.php?wakka=llAxisAngle2Rot