Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Move Avatar Depending on Which Way I'm Facing?

Douglas Callahan
Fresh Prince Of SL
Join date: 2 Jul 2004
Posts: 349
06-19-2008 03:41
Hey everyone, long time no post,

I'm working on a script which I want to move me to the right and left, depending on which way I'm facing. The script is in an attachment and the movement is working, just not in the right directions.

How can I figure out which way my av is facing and therefore what "right" is? And would there be a way to, say if my avatar was facing 30 degrees east of north, to have it so when I move to the right, it moves along the east west axis, as opposed to right at 30 degrees south of west?

I'm terrible at everything dealing with rots, so here's all I have so far:

From: someone
if (pressed & CONTROL_ROT_RIGHT)
{
pos = llGetPos() - <0,1,0>;
targ = llTarget(pos, .5);
llMoveToTarget(pos, .1);
}


Thanks in advance for all the help :)
_____________________
Other than that, Mrs. Lincoln, how was the play?
Jillian Callahan
Rotary-winged Neko Girl
Join date: 24 Jun 2004
Posts: 3,766
06-19-2008 03:47
Easy peasy.

CODE
if (pressed & CONTROL_ROT_RIGHT)
{
pos = llGetPos() - llRot2Left(llGetRot()); // for going left, add.
// llRot2Left, llRot2Fwd, llRot2Up all take a
// rotation and give you "one meter" in their respective directions.
targ = llTarget(pos, .5);
llMoveToTarget(pos, .1);
}
Douglas Callahan
Fresh Prince Of SL
Join date: 2 Jul 2004
Posts: 349
06-19-2008 03:52
Oh sick thanks. Stupid me :p .

So does that move along the x and y axes or just left/right from the way you're facing?
_____________________
Other than that, Mrs. Lincoln, how was the play?
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
06-19-2008 13:37
That's left and right according to the direction you are facing. If you want to constrain it to the East-West direction (x-axis) or North-South direction (y-axis), I'd do it like this:

CODE

vector getConstrainedLeftDir()
{
vector avatarLeft = llRot2Left(llGetRot());
if (llFabs(avatarLeft.x) >= llFabs(avatarLeft.y))
{
if (avatarLeft.x >= 0)
{
return <1.0, 0.0, 0.0>
} else
{
return <-1.0, 0.0, 0.0>
}
} else
{
if (avatarLeft.y >= 0)
{
return <0.0, 1.0, 0.0>
} else
{
return <0.0, -1.0, 0.0>
}
}
}

vector getConstrainedRightDir()
{
return -getConstrainedLeftDir();
}
Douglas Callahan
Fresh Prince Of SL
Join date: 2 Jul 2004
Posts: 349
06-19-2008 15:12
That works perfectly, thanks for all the help ;)
_____________________
Other than that, Mrs. Lincoln, how was the play?